【发布时间】:2015-11-02 16:55:26
【问题描述】:
这个错误很奇怪:
-[<>.Tips setTipName:]: unrecognized selector sent to instance <>
名称 setTipName 不会出现在代码中的任何地方,但有一个变量tipName(注意小写“t”
我正在尝试在 CoreData 实体中插入一行
class Tips: NSManagedObject {
@NSManaged var sectionNumber: NSNumber
@NSManaged var tipDescription: String
@NSManaged var viewName: String
@NSManaged var tipName: String
@NSManaged var tipOrder: NSNumber
@NSManaged var tipType: String
@NSManaged var tipLinkName: String
}
这是插入的代码:
func createNewTips ()
{
// set create all switches and set to off
var error: NSError? = nil
var textCount = textArray.count
for var i = 0; i<textCount; ++i
{
var newTip = NSEntityDescription.insertNewObjectForEntityForName("Tips", inManagedObjectContext: managedObjectContext!) as! Tips
newTip.viewName = viewName
newTip.tipName = textArray [i].tipName
NSLog("after tipName")
newTip.tipDescription = textArray[i].tipDescription
NSLog("after set tipDescription")
newTip.tipOrder = textArray[i].tipOrder
NSLog("after set tipOrder")
newTip.sectionNumber = textArray[i].sectionNumber
NSLog("after set sectionNumber")
newTip.tipType = textArray[i].type
NSLog("after set type")
newTip.tipLinkName = textArray[i].tipLinkName
var error: NSError? = nil
if !managedObjectContext!.save(&error) {
NSLog("error &d", error!)
abort()
} // end save
} // end loop
} // end of createNewSwitches
我已经多次重新创建数据模型
我还更改了属性的顺序,错误发生在不同的属性上。我注意到,当我将 viewName 属性移到列表后面时,它似乎是第一个属性。
这是 textArray 中的代码
var textArray:[(sectionNumber: Int, tipOrder: Int, tipName: String, tipDescription: String, type: String, tipLinkName:String)] =
[
(1,0,"sw1","Check in and around your home for damage","text",""),
(1,1,"sw2","Dispose of any spoiled or contaminated foods, especially after a power outage. If you’re not sure, throw it out. You can check the food safety tips below","text",""),
(1,2,"sw3","Encourage family members to talk about their experience and their feelings, especially children","text",""),
(1,3,"sw4","Contact other family members to let them know that you are safe","text",""),
(2,0,"sw5","Check Utilities","link",""),
(3,0,"sw6","Food Safety Tips","link",""),
]
对此有什么建议吗?
【问题讨论】:
-
错误信息看起来不完整——尖括号之间应该有一些东西。
-
模型构建器中提示实体的类是否设置为“提示”?
-
当您使用
propertyName = someValue;设置属性时,您正在调用setPropertyName方法。 -
尖括号是我删除不相关数据的方式
-
@PatriciaW- 如果你不理解错误信息,你就不知道什么是相关的。