![](/img/trans.png)
[英]Cannot invoke initializer for type '' with an argument list of type ''
[英]Cannot invoke initializer for type 'NSSet' with an argument list of type '(array: [NSData?])'
更新到Swift 2.0時出現此錯誤:
無法使用類型為((array:[NSData?]))的參數列表來調用類型為'NSSet'的初始化程序
我已經進行了搜索,但是仍然無法解決。
var object:UIImageView = UIImageView(frame: CGRectMake(0, 0, result.size.width, result.size.height))
object.image = UIImage(named: "image_default")
let element = NSEntityDescription.insertNewObjectForEntityForName("XKIMAGEVIEW", inManagedObjectContext: CoreDataUtil.sharedInstance.managedObjectContext!) as! XKIMAGEVIEW
element.image = NSSet(array:[UIImageJPEGRepresentation(object.image!, 1)])
最后一行只是有錯誤
似乎NSData無法包含在數組中
關於如何解決此問題的任何想法?
UIImageJPEGRepresentation
返回一個可選參數, NSSet
不接受可選參數。
只需解開可選:
NSSet(array:[UIImageJPEGRepresentation(object.image!, 1)!])
或者,如果圖像表示形式nil
使用可選綁定
if let imageData = UIImageJPEGRepresentation(object.image!, 1) {
element.image = NSSet(array:[imageData])
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.