我一直在寻找类似的问题,但我仍然不明白我的情况在哪里出错。得到此错误:
MyAwesomeApp[3481:1330310] -[Session setClient:]: unrecognized selector sent to instance 0x16e05de0
2015-03-15 07:30:29.990 MyAwesomeApp[3481:1330310] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Session setClient:]: unrecognized selector sent to instance 0x16e05de0'
*** First throw call stack:
(0x28e1045f 0x36ca6c8b 0x28e15879 0x28e13797 0x28d45008 0x646c4 0x628b4 0x62ba4 0x2c35de7f 0x2c4c1b35 0x2c35de7f 0x2c35de21 0x2c348c43 0x2c35d88d 0x2c35d567 0x2c356e31 0x2c32d759 0x2c5a12f9 0x2c32c1a9 0x28dd6fbf 0x28dd63cf 0x28dd4a35 0x28d223b1 0x28d221c3 0x3034f201 0x2c38c43d 0xa7a24 0xa7a60 0x37232aaf)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
执行此代码时:
@IBAction func saveButton(sender: AnyObject) {
if session != nil {
editSession()
} else {
createSession()
}
navigationController?.popViewControllerAnimated(true)
}
func editSession() {
session?.sessionTitle = sessionTitleTxt.text
managedObjectContext?.save(nil)
}
func createSession() {
let entityDescription = NSEntityDescription.entityForName("Session", inManagedObjectContext: managedObjectContext!)
let newSession = Session(entity: entityDescription!, insertIntoManagedObjectContext: managedObjectContext)
if sessionTitleTxt.text == "" {
newSession.sessionTitle = "Untitled Session"
} else {
newSession.sessionTitle = sessionTitleTxt.text
newSession.client = self.client!
}
managedObjectContext?.save(nil)
SessionsTVC?.client = newSession.client
}
会话类是:
import Foundation
import CoreData
@objc(Session)
class Session: NSManagedObject {
@NSManaged var sessionDate: String
@NSManaged var sessionTitle: String
@NSManaged var sessionNotes: String
@NSManaged var sessionExercises: NSSet
@NSManaged var client: Client
}
任何人都可以帮助我吗?我之前得到的客户端变量为零,因为我有几个我感到困惑的段,但现在我得到了这个选择器错误而不确定如何继续前进。
感谢您的任何建议!
答案 0 :(得分:0)
你得到的错误,
MyAwesomeApp[3481:1330310] -[Session setClient:]: unrecognized selector sent to instance 0x16e05de0
2015-03-15 07:30:29.990 MyAwesomeApp[3481:1330310] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Session setClient:]: unrecognized selector sent to instance 0x16e05de0'
在无法找到要执行的方法时发生。这可以抛出,因为方法不存在,或者在错误的对象上调用它。在您的特定情况下,正在setClient
对象上调用方法Session
,该对象存储在0x16e05de0
的内存地址
确保setClient方法存在,并且应该在该Session对象上调用。
这是一个很好的链接,可以帮助您进行调试:
http://www.raywenderlich.com/10209/my-app-crashed-now-what-part-1
希望这会有所帮助!!