【发布时间】:2017-01-27 05:26:41
【问题描述】:
我正在尝试在 swift 2 中使用 PropertyListSerialization 制作字典。但它不断给出这个错误:
"can not convert value of type 'Int' to expected argument type 'NSPropertyListReadOptions'
我的代码行是:
NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue()) {response,data,error in
if data != nil {
let datasourceDictionary = try! NSPropertyListSerialization.propertyListWithData(data! ,options:Int(NSPropertyListMutabilityOptions.Immutable.rawValue), format: nil)
还有这个:
let datasourceDictionary = try! NSPropertyListSerialization.propertyListWithData(data! ,options:Int(NSPropertyListMutabilityOptions.Immutable.rawValue), format: nil)
然后我必须遍历字典:
for(key, value): (AnyObject, AnyObject) in datasourceDictionary {
let name = key as? String
let url = NSURL(string:value as? String ?? "")
if name != nil && url != nil {
let photoRecord = PhotoRecord(name:name!, url:url!)
self.photos.append(photoRecord)
}
}
【问题讨论】: