Android developer and iOS newb here. I have an app I'm migrating to iOS. I'm learning Xcode and Swift at the same time so be gentle please! :)
My question is I simply want to save/retrieve a class such as below (in Java):
public class CardDeck implements Parcelable{
private ArrayList<Profile> cards;
private int location;
public CardDeck(){
this.cards = new ArrayList<>();
this.location = 0;
//this.numCards = 0;
}
public CardDeck(ArrayList<Profile> cards) {
this.cards = cards;
this.location = 0;
//this.numCards = cards.size();
}
protected CardDeck(Parcel in) {
cards = in.createTypedArrayList(Profile.CREATOR);
//numCards = in.readInt();
location = in.readInt();
}
}
I would like to save/retrieve a CardDeck object that contains an Array of Profiles. My initial readings makes me think you cannot do this with either UserDefaults or NSCoding because plist files cannot contain a custom data type like Profile. Did I get that right? UserDefaults are for standard data types (bool, int, String, etc.) and NSCoding can handle a custom object such as CardDeck BUT CardDeck can only have members that are standard data types.
How would you pros handle my problem? Core Data?
I handled this in Android by using SharedPreferences
and Gson.toJson(cardDeck)
.
Thanks for reading!