Last active
July 20, 2017 20:10
-
-
Save staycreativedesign/1e93f75bb44d061119cc0866719d1cf5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"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" | |
} | |
] | |
} | |
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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