func toAnyObject() -> AnyObject {
return [
"name": title,
"addedByUser": subtitle,
"completed": imageURL
]
}
以上代码生成以下错误:返回夫特字典作为AnyObject
Contextual type 'AnyObject' cannot be used with dictionary literal
更新:我想创建的toAnyObject功能,并利用它在火力地堡应用。我得到如下:
, reason: '(setValue:) Cannot store object of type _SwiftValue at name. Can only store objects of type NSNumber, NSString, NSDictionary, and NSArray.'
let rootRef = FIRDatabase.database().reference()
let categoriesRef = rootRef.child("categories")
let annuals = FlowerCategory(id: 1, title: "Annuals",subtitle :"Plants that just last one season. These plants will die in the winter. ", imageURL: "annuals.jpg")
let perennials = FlowerCategory(id: 2, title: "Perennials",subtitle :"Plants come back year after year. These are also very less expensive", imageURL: "Perennial.jpg")
let flowerCategories = [annuals,perennials]
for flowerCategory in flowerCategories {
let categoryRef = categoriesRef.child("category")
categoryRef.setValue(flowerCategory.toAnyObject()) <- THIS LINE ERROR
}
'返回[ “名”:标题, “addedByUser”:字幕, “完成”:IMAGEURL ]作为AnyObject' –