我在Obj-C中做了很多NSCoding归档,但我不确定它如何处理Swift中的结构,也不确定具有可选值的数组.这是我的代码:
public struct SquareCoords {
var x: Int, y: Int
}
Run Code Online (Sandbox Code Playgroud)
这是我需要存储的类:
public class Player: NSCoding {
var playerNum: Int
var name = ""
private var moveHistory: [SquareCoords?] = []
init (playerNum: Int, name: String) {
self.playerNum = playerNum
self.name = name
}
public required init(coder aDecoder: NSCoder!) {
playerNum = aDecoder.decodeIntegerForKey("playerNumKey")
name = aDecoder.decodeObjectForKey("nameKey") as String
moveHistory = aDecoder.decodeObjectForKey("moveHistoryKey") as [SquareCoords?]
}
public func encodeWithCoder(aCoder: NSCoder!) {
aCoder.encodeInteger(playerNum, forKey: "playerNumKey")
aCoder.encodeObject(name, forKey: "nameKey")
aCoder.encodeObject(moveHistory, forKey: "moveHistoryKey")
}
...
Run Code Online (Sandbox Code Playgroud)
在编码器init的最后一行,我在XCode中收到以下错误消息: …
我在Toki Pona和Dothraki有一个带有界面语言的iPhone应用程序,它没有ISO 639-3代码.根据ISO 639-3标准,您可以使用范围qaa-qtz来表示我已经完成的本地语言(Toki Pona = qtp,Dothraki = qdt),但仍然可以从XCode"无法识别的区域设置"获得警告.
看起来我可能能够扩展主bundle类,但查看文档,似乎没有任何东西与添加非ISO语言有关.我也知道文本"如果有必要,你可以使用NSBundle类或Core Foundation软件包功能所不知道的语言或语言环境代码.例如,你可以为一种非语言创建自己的语言指示符.但已列入ISO惯例或在Xcode中作为语言提供." 在https://developer.apple.com/library/archive/documentation/MacOSX/Conceptual/BPInternational/LanguageandLocaleIDs/LanguageandLocaleIDs.html的最后
无论如何,我大多想要摆脱这个警告.任何帮助将不胜感激!