Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Simen Anthonsen
Simen Anthonsen
1,097 Points

Store objects in Parse

Let say I have created a deck of cards like this

                                      enum CardSuit: Int {
    case Diamonds = 0, Clubs, Hearts, Spades
}
enum CardValue: Int {
    case Two = 2, Three, Four, Five, Six, Seven, Eight, Nine, Ten, Jack, Queen, King, Ace
}
class Card {
    var value: CardValue
    var suit: CardSuit

    init(value initialValue: CardValue, suit initialSuit: CardSuit) {
        value = initialValue
        suit = initialSuit
    }
}


let twoOfHearts = Card(value: .Two, suit: .Hearts)
let threeOfHearts = Card(value: .Three, suit: .Hearts)
let fourOfHearts = Card(value: .Four, suit: .Hearts)
let fiveOfHearts = Card(value: .Five, suit: .Hearts)
let sixOfHearts = Card(value: .Six, suit: .Hearts)
let sevenOfHearts = Card(value: .Seven, suit: .Hearts)
let eightOfHearts = Card(value: .Eight, suit: .Hearts)
let nineOfHearts = Card(value: .Nine, suit: .Hearts)
let tenOfHearts = Card(value: .Ten, suit: .Hearts)
let jackoOfHearts = Card(value: .Jack, suit: .Hearts)
let queenOfHearts = Card(value: .Queen, suit: .Hearts)
let kingOfHearts = Card(value: .King, suit: .Hearts)
let aceOfHearts = Card(value: .Ace, suit: .Hearts)

How do I store these instances in Parse?

Nathan Tallack
Nathan Tallack
22,160 Points

Can we have some context? Perhaps reference to the library you are trying to use?

1 Answer

Michael Reining
Michael Reining
10,101 Points

Just follow the Parse SDK. They have a great example here how to store / save objects in Parse.

https://parse.com/docs/ios/guide#objects

Try to model their example and once you get it working, just tweak it to change it so that you are saving cards or an array of cards in Parse.

I hope that helps,

Mike

PS: Thanks to the awesome resources on Team Treehouse, I just launched my first app. :-)

Code! Learn how to program with Swift

Simen Anthonsen
Simen Anthonsen
1,097 Points

Thanks! and congratulations :D