Skip to content

Instantly share code, notes, and snippets.

@staycreativedesign
Last active July 20, 2017 20:10
Show Gist options
  • Save staycreativedesign/1e93f75bb44d061119cc0866719d1cf5 to your computer and use it in GitHub Desktop.
Save staycreativedesign/1e93f75bb44d061119cc0866719d1cf5 to your computer and use it in GitHub Desktop.
[
{
"id": 0,
"name": "comida",
"price": 0.99,
"description": "this is the description",
"deckImage": "this is a UIImage",
"deckBgImage": "this is a UIImage",
"bought": false,
"cards": [
{
"name": "card name 1"
},
{
"name": "card name 2"
},
{
"name": "card name 3"
}
]
},
{
"id": 1,
"name": "comida",
"price": 0.99,
"description": "this is the description",
"deckImage": "this is a UIImage",
"deckBgImage": "this is a UIImage",
"bought": false,
"cards": [
{
"name": "card name 1"
},
{
"name": "card name 2"
},
{
"name": "card name 3"
}
]
}
]
guard let path = Bundle.main.path(forResource: "files", ofType: "json") else { return print("file no existo") }
let url = URL(fileURLWithPath: path)
do {
let data = try Data(contentsOf: url)
let json = try JSONSerialization.jsonObject(with: data, options: .mutableContainers)
guard let array = json as? [Any] else { return }
for obj in array {
var totalCards = [String]()
guard let deck = obj as? [String: Any] else { return }
guard let deckName = deck["name"] as? String else { return }
guard let deckDescription = deck["description"] as? String else { return }
guard let deckImage = deck["deckImage"] as? String else { return }
guard let deckBgImage = deck["deckBgImage"] as? String else { return }
guard let cards = deck["cards"]! as? [[String: String]] else { return }
for card in cards {
let currentCard = card["name"]
print(currentCard!)
totalCards.append(currentCard!)
}
let finalizedDeck = createDeck(withName: deckName, withCards: totalCards, description: deckDescription, deckImage: deckImage, descriptionBg: deckBgImage)
boughtDecks.append(finalizedDeck)
}
} catch {
print(error)
}
}
Cannot convert value of type 'String' to expected argument type 'UIImage'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment