我很困惑,因爲這只是停止工作沒有地方。我不確定它是否與我的綁定有關,或者它們是否被棄用或者交易是什麼,但之前沒有問題,我沒有任何值爲零。我有它的工作很長一段時間,現在我一直在網上收到此錯誤:意外地發現零,同時展開一個可選的值JSON swift
self.arrayControllerNames.addObject(names)
Controller.swift
import Cocoa
class Controller: NSObject {
@IBOutlet weak var arrayControllerNames: NSArrayController!
@IBOutlet weak var arrayControllerPrices: NSArrayController!
var names: NSMutableArray = NSMutableArray()
var prices: NSMutableArray = NSMutableArray()
var descriptions: NSMutableArray = NSMutableArray()
var images: NSMutableArray = NSMutableArray()
var videos: NSMutableArray = NSMutableArray()
var downloads: NSMutableArray = NSMutableArray()
override func awakeFromNib() {
let url = NSURL(string: "http://url")
let request = NSURLRequest(url: url as! URL)
let session = URLSession(configuration: URLSessionConfiguration.default)
let task = session.dataTask(with: request as URLRequest) { (data,response,error) -> Void in
if error == nil {
let swiftyJSON = JSON(data:data!)
print(swiftyJSON)
let products = swiftyJSON[].arrayValue
for product in products{
let names = product["product_name"].stringValue
//let prices = product["product_price"].stringValue
//let descriptions = product["product_description"].stringValue
//let images = product["product_description"].stringValue
//let videos = product["product_description"].stringValue
//let downloads = product["product_description"].stringValue
self.arrayControllerNames.addObject(names)
//self.arrayControllerPrices.addObject(prices)
//self.arrayControllerPrices.addObject(descriptions)
//self.arrayControllerPrices.addObject(images)
//self.arrayControllerPrices.addObject(videos)
//self.arrayControllerPrices.addObject(downloads)
}
} else{
print("Error")
}
}
task.resume()
}
}
「NSArrayController」根本不能用多個數組作爲數據源。使用自定義類作爲模型。和**不要在Swift **中使用'NSMutableArray/NSMutableDictionary'。解決那些暗示這些教程。陣列控制器是否在Interface Builder中連接? – vadian
是我的陣列控制器連接在接口 –