【发布时间】:2014-07-13 21:59:52
【问题描述】:
我正在尝试使用 plist 来保存字典数组。一切似乎都很好,除了当我尝试遍历数组的每个元素时。在这种情况下,我使用 NSArrays 和 NSDictionarys。
在下面的示例中,albumInfo 是 NSDictionary。键 "Title" 与字符串对象链接。我正在使用一种名为addAlbumInfo 的方法,它的参数都是Strings,除了"price:"
请帮忙。
var pathToAlbumsPlist:NSString = NSBundle.mainBundle().pathForResource("AlbumArray", ofType: "plist");
var defaultAlbumPlist:NSArray = NSArray(contentsOfFile: pathToAlbumsPlist);
for albumInfo:NSDictionary in defaultAlbumPlist {
self.addAlbumWithTitle(
albumInfo["title"], //Says it is not convertable to a string
artist: albumInfo["artist"],
summary: albumInfo["summary"],
price: albumInfo["price"].floatValue,
locationInStore: albumInfo["locationInStore"]
);
}
【问题讨论】:
标签: ios nsarray swift nsdictionary plist