Stabilize iOS/watchOS/tvOS apps and add cross-platform audit remediation
This commit is contained in:
@@ -8,100 +8,56 @@
|
||||
import Foundation
|
||||
|
||||
class PreviewData {
|
||||
private class func decodeFromBundle<T: Decodable>(_ fileName: String,
|
||||
as type: T.Type) -> T? {
|
||||
guard let filepath = Bundle.main.path(forResource: fileName, ofType: "json"),
|
||||
let data = try? Data(NSData(contentsOfFile: filepath)) else {
|
||||
return nil
|
||||
}
|
||||
|
||||
return try? JSONDecoder().decode(T.self, from: data)
|
||||
}
|
||||
|
||||
class func workout() -> Workout {
|
||||
let filepath = Bundle.main.path(forResource: "WorkoutDetail", ofType: "json")!
|
||||
let data = try! Data(NSData(contentsOfFile: filepath))
|
||||
let workout = try! JSONDecoder().decode(Workout.self, from: data)
|
||||
return workout
|
||||
if let workout = decodeFromBundle("WorkoutDetail", as: Workout.self) {
|
||||
return workout
|
||||
}
|
||||
if let firstWorkout = allWorkouts().first {
|
||||
return firstWorkout
|
||||
}
|
||||
|
||||
return Workout(id: -1, name: "Unavailable")
|
||||
}
|
||||
|
||||
class func allWorkouts() -> [Workout] {
|
||||
if let filepath = Bundle.main.path(forResource: "AllWorkouts", ofType: "json") {
|
||||
do {
|
||||
let data = try Data(NSData(contentsOfFile: filepath))
|
||||
let workout = try JSONDecoder().decode([Workout].self, from: data)
|
||||
return workout
|
||||
} catch {
|
||||
print(error)
|
||||
fatalError()
|
||||
}
|
||||
} else {
|
||||
fatalError()
|
||||
}
|
||||
decodeFromBundle("AllWorkouts", as: [Workout].self) ?? []
|
||||
}
|
||||
|
||||
class func parseExercises() -> [Exercise] {
|
||||
if let filepath = Bundle.main.path(forResource: "Exercises", ofType: "json") {
|
||||
do {
|
||||
let data = try Data(NSData(contentsOfFile: filepath))
|
||||
let exercises = try JSONDecoder().decode([Exercise].self, from: data)
|
||||
return exercises
|
||||
} catch {
|
||||
print(error)
|
||||
fatalError()
|
||||
}
|
||||
} else {
|
||||
fatalError()
|
||||
}
|
||||
decodeFromBundle("Exercises", as: [Exercise].self) ?? []
|
||||
}
|
||||
|
||||
class func parseEquipment() -> [Equipment] {
|
||||
if let filepath = Bundle.main.path(forResource: "Equipment", ofType: "json") {
|
||||
do {
|
||||
let data = try Data(NSData(contentsOfFile: filepath))
|
||||
let equipment = try JSONDecoder().decode([Equipment].self, from: data)
|
||||
return equipment
|
||||
} catch {
|
||||
print(error)
|
||||
fatalError()
|
||||
}
|
||||
} else {
|
||||
fatalError()
|
||||
}
|
||||
decodeFromBundle("Equipment", as: [Equipment].self) ?? []
|
||||
}
|
||||
|
||||
class func parseMuscle() -> [Muscle] {
|
||||
if let filepath = Bundle.main.path(forResource: "AllMuscles", ofType: "json") {
|
||||
do {
|
||||
let data = try Data(NSData(contentsOfFile: filepath))
|
||||
let muscles = try JSONDecoder().decode([Muscle].self, from: data)
|
||||
return muscles
|
||||
} catch {
|
||||
print(error)
|
||||
fatalError()
|
||||
}
|
||||
} else {
|
||||
fatalError()
|
||||
}
|
||||
decodeFromBundle("AllMuscles", as: [Muscle].self) ?? []
|
||||
}
|
||||
|
||||
class func parseRegisterdUser() -> RegisteredUser {
|
||||
if let filepath = Bundle.main.path(forResource: "RegisteredUser", ofType: "json") {
|
||||
do {
|
||||
let data = try Data(NSData(contentsOfFile: filepath))
|
||||
let muscles = try JSONDecoder().decode(RegisteredUser.self, from: data)
|
||||
return muscles
|
||||
} catch {
|
||||
print(error)
|
||||
fatalError()
|
||||
}
|
||||
} else {
|
||||
fatalError()
|
||||
}
|
||||
decodeFromBundle("RegisteredUser", as: RegisteredUser.self) ??
|
||||
RegisteredUser(id: -1,
|
||||
firstName: nil,
|
||||
lastName: nil,
|
||||
image: nil,
|
||||
nickName: nil,
|
||||
token: nil,
|
||||
email: nil,
|
||||
hasNSFWToggle: nil)
|
||||
}
|
||||
|
||||
class func parseCompletedWorkouts() -> [CompletedWorkout] {
|
||||
if let filepath = Bundle.main.path(forResource: "CompletedWorkouts", ofType: "json") {
|
||||
do {
|
||||
let data = try Data(NSData(contentsOfFile: filepath))
|
||||
let muscles = try JSONDecoder().decode([CompletedWorkout].self, from: data)
|
||||
return muscles
|
||||
} catch {
|
||||
print(error)
|
||||
fatalError()
|
||||
}
|
||||
} else {
|
||||
fatalError()
|
||||
}
|
||||
decodeFromBundle("CompletedWorkouts", as: [CompletedWorkout].self) ?? []
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user