【发布时间】:2018-09-11 16:35:50
【问题描述】:
Android 开发者和 iOS 新手在这里。我有一个要迁移到 iOS 的应用程序。我正在同时学习 Xcode 和 Swift,所以请温柔一点! :)
我的问题是我只是想保存/检索如下类(在 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();
}
}
我想保存/检索包含配置文件数组的 CardDeck 对象。我最初的阅读使我认为您不能使用 UserDefaults 或 NSCoding 执行此操作,因为 plist 文件不能包含自定义数据类型,例如 Profile。我做对了吗? UserDefaults 用于标准数据类型(bool、int、String 等),NSCoding 可以处理自定义对象,例如 CardDeck 但 CardDeck 只能具有标准数据类型的成员。
专业人士会如何处理我的问题?核心数据?
我在 Android 中使用 SharedPreferences 和 Gson.toJson(cardDeck) 处理了这个问题。
感谢阅读!
【问题讨论】:
标签: ios swift core-data nsuserdefaults nscoding