Swift Bindings KVO / KVC问题

时间:2014-08-13 15:06:15

标签: cocoa swift cocoa-bindings xcode6 osx-yosemite-beta

有没有人成功地在Swift上运行绑定(Xcode6 Beta 5)? 我正在开发一个基于文档的应用程序,甚至只是尝试绑定一个数组,如:

dynamic var myArray: NSMutableArray = []

到" contentArray"一个NSArrayController失败并给出以下错误
线程1:EXC_BAD_ACCESS(代码= 1,地址= 0x0)
知道为什么它不起作用吗?
对我而言,KVO / KVC遵守Swift似乎存在问题 这是调用堆栈的一部分:

    Foundation`-[NSObject(NSKeyValueObserverRegistration) addObserver:forKeyPath:options:context:]:
0x7fff983652ff:  pushq  %rbp
0x7fff98365300:  movq   %rsp, %rbp
0x7fff98365303:  pushq  %r15
0x7fff98365305:  pushq  %r14
0x7fff98365307:  pushq  %r13
0x7fff98365309:  pushq  %r12
0x7fff9836530b:  pushq  %rbx
0x7fff9836530c:  subq   $0x58, %rsp
0x7fff98365310:  movq   %r9, %r13
0x7fff98365313:  movq   %r8, %r12
0x7fff98365316:  movq   %rcx, %r15
0x7fff98365319:  movq   %rdx, %r14
0x7fff9836531c:  movq   %rdi, %rbx
0x7fff9836531f:  leaq   -0x1ab019ce(%rip), %rax   ; _NSKeyValueObserverRegistrationLock
0x7fff98365326:  movq   (%rax), %rdi
0x7fff98365329:  testq  %rdi, %rdi
0x7fff9836532c:  je     0x7fff9836533b            ; -[NSObject(NSKeyValueObserverRegistration) addObserver:forKeyPath:options:context:] + 60
0x7fff9836532e:  movq   -0x1ab1e5dd(%rip), %rsi   ; "lock"
0x7fff98365335:  callq  *-0x1abc5a53(%rip)        ; (void *)0x00007fff90f410c0: objc_msgSend
0x7fff9836533b:  movq   %rbx, %rdi
0x7fff9836533e:  callq  0x7fff985d1600            ; symbol stub for: object_getClass
0x7fff98365343:  movq   %rax, %rdi
0x7fff98365346:  movq   %r15, %rsi
0x7fff98365349:  callq  0x7fff9833e04d            ; NSKeyValuePropertyForIsaAndKeyPath
0x7fff9836534e:  movq   -0x1ab1c28d(%rip), %rsi   ; "_addObserver:forProperty:options:context:"
0x7fff98365355:  movq   %rbx, %rdi
0x7fff98365358:  movq   %r14, %rdx
0x7fff9836535b:  movq   %rax, %rcx
0x7fff9836535e:  movq   %r12, %r8
0x7fff98365361:  movq   %r13, %r9
0x7fff98365364:  callq  *-0x1abc5a82(%rip)        ; (void *)0x00007fff90f410c0: objc_msgSend
0x7fff9836536a:  xorl   %ebx, %ebx
0x7fff9836536c:  leaq   -0x1ab01a1b(%rip), %rax   ; _NSKeyValueObserverRegistrationLock
0x7fff98365373:  movq   (%rax), %rdi
0x7fff98365376:  testq  %rdi, %rdi
0x7fff98365379:  je     0x7fff98365388            ; -[NSObject(NSKeyValueObserverRegistration) addObserver:forKeyPath:options:context:] + 137
0x7fff9836537b:  movq   -0x1ab1e622(%rip), %rsi   ; "unlock"
0x7fff98365382:  callq  *-0x1abc5aa0(%rip)        ; (void *)0x00007fff90f410c0: objc_msgSend
0x7fff98365388:  testb  %bl, %bl
0x7fff9836538a:  jne    0x7fff983654e8            ; -[NSObject(NSKeyValueObserverRegistration) addObserver:forKeyPath:options:context:] + 489
0x7fff98365390:  addq   $0x58, %rsp
0x7fff98365394:  popq   %rbx
0x7fff98365395:  popq   %r12
0x7fff98365397:  popq   %r13
0x7fff98365399:  popq   %r14
0x7fff9836539b:  popq   %r15
0x7fff9836539d:  popq   %rbp
0x7fff9836539e:  retq   
0x7fff9836539f:  movq   %rdx, %rcx
0x7fff983653a2:  movq   %rax, -0x30(%rbp)
0x7fff983653a6:  cmpl   $0x2, %ecx
0x7fff983653a9:  jne    0x7fff983654cf            ; -[NSObject(NSKeyValueObserverRegistration) addObserver:forKeyPath:options:context:] + 464
0x7fff983653af:  movq   -0x30(%rbp), %rdi
0x7fff983653b3:  callq  0x7fff985d152e            ; symbol stub for: objc_begin_catch
0x7fff983653b8:  movq   %rax, %rcx
0x7fff983653bb:  movq   %rcx, -0x30(%rbp)
0x7fff983653bf:  movq   -0x1ab1d966(%rip), %rax   ; "userInfo"
0x7fff983653c6:  movq   %rcx, %rdi
0x7fff983653c9:  movq   %rax, %rsi
0x7fff983653cc:  callq  *-0x1abc5aea(%rip)        ; (void *)0x00007fff90f410c0: objc_msgSend
0x7fff983653d2:  movq   %rax, -0x38(%rbp)
0x7fff983653d6:  movq   -0x1ab1e105(%rip), %rax   ; "name"
0x7fff983653dd:  movq   -0x30(%rbp), %rdi
0x7fff983653e1:  movq   %rax, %rsi
0x7fff983653e4:  callq  *-0x1abc5b02(%rip)        ; (void *)0x00007fff90f410c0: objc_msgSend
0x7fff983653ea:  leaq   -0x1abc1851(%rip), %rcx   ; NSUndefinedKeyException
0x7fff983653f1:  movq   (%rcx), %rdx
0x7fff983653f4:  movq   %rdx, -0x30(%rbp)
0x7fff983653f8:  movq   -0x1ab1f1e7(%rip), %rcx   ; "isEqualToString:"
0x7fff983653ff:  movq   %rax, %rdi
0x7fff98365402:  movq   %rcx, %rsi
0x7fff98365405:  callq  *-0x1abc5b23(%rip)        ; (void *)0x00007fff90f410c0: objc_msgSend
0x7fff9836540b:  testb  %al, %al
0x7fff9836540d:  je     0x7fff983654c1            ; -[NSObject(NSKeyValueObserverRegistration) addObserver:forKeyPath:options:context:] + 450
0x7fff98365413:  movq   -0x1ab1ee22(%rip), %rax   ; "objectForKey:"
0x7fff9836541a:  leaq   -0x1abb20e1(%rip), %rcx   ; @"NSTargetObjectUserInfoKey"
0x7fff98365421:  movq   -0x38(%rbp), %rdi
0x7fff98365425:  movq   %rax, %rsi
0x7fff98365428:  movq   %rcx, %rdx
0x7fff9836542b:  callq  *-0x1abc5b49(%rip)        ; (void *)0x00007fff90f410c0: objc_msgSend
0x7fff98365431:  cmpq   %rbx, %rax
0x7fff98365434:  jne    0x7fff983654c1            ; -[NSObject(NSKeyValueObserverRegistration) addObserver:forKeyPath:options:context:] + 450
0x7fff9836543a:  movq   -0x1ab166a1(%rip), %rax   ; (void *)0x00007fff7c5612d0: NSException
0x7fff98365441:  movq   %rax, -0x40(%rbp)
0x7fff98365445:  movq   %rbx, %rdi
0x7fff98365448:  callq  0x7fff983449c5            ; NSClassFromObject
0x7fff9836544d:  movq   %rax, -0x48(%rbp)
0x7fff98365451:  movq   %r14, %rdi
0x7fff98365454:  callq  0x7fff983449c5            ; NSClassFromObject
0x7fff98365459:  movq   %rax, -0x50(%rbp)
0x7fff9836545d:  movq   -0x1ab1ee6c(%rip), %rax   ; "objectForKey:"
0x7fff98365464:  leaq   -0x1abb210b(%rip), %rcx   ; @"NSUnknownUserInfoKey"
0x7fff9836546b:  movq   -0x38(%rbp), %rdi
0x7fff9836546f:  movq   %rax, %rsi
0x7fff98365472:  movq   %rcx, %rdx
0x7fff98365475:  callq  *-0x1abc5b93(%rip)        ; (void *)0x00007fff90f410c0: objc_msgSend
0x7fff9836547b:  movq   -0x1ab1f19a(%rip), %rsi   ; "raise:format:"
0x7fff98365482:  movq   %rax, 0x28(%rsp)
0x7fff98365487:  movq   %r13, 0x20(%rsp)
0x7fff9836548c:  movq   %r12, 0x18(%rsp)
0x7fff98365491:  movq   %r15, 0x10(%rsp)
0x7fff98365496:  movq   %r14, 0x8(%rsp)
0x7fff9836549b:  movq   -0x50(%rbp), %rax
0x7fff9836549f:  movq   %rax, (%rsp)
0x7fff983654a3:  leaq   -0x1abae80a(%rip), %rcx   ; @"[<%@ %p> addObserver:<%@ %p> forKeyPath:@"%@" options:%lu context:%p] was sent to an object that is not KVC-compliant for the "%@" property."
0x7fff983654aa:  xorl   %eax, %eax
0x7fff983654ac:  movq   -0x30(%rbp), %rdx
0x7fff983654b0:  movq   -0x40(%rbp), %rdi
0x7fff983654b4:  movq   -0x48(%rbp), %r8
0x7fff983654b8:  movq   %rbx, %r9
0x7fff983654bb:  callq  *-0x1abc5bd9(%rip)        ; (void *)0x00007fff90f410c0: objc_msgSend
0x7fff983654c1:  callq  0x7fff985d156a            ; symbol stub for: objc_exception_rethrow
0x7fff983654c6:  movq   %rax, -0x30(%rbp)
0x7fff983654ca:  callq  0x7fff985d155e            ; symbol stub for: objc_end_catch
0x7fff983654cf:  movq   -0x30(%rbp), %rdi
0x7fff983654d3:  callq  0x7fff985d152e            ; symbol stub for: objc_begin_catch
0x7fff983654d8:  movb   $0x1, %bl
0x7fff983654da:  jmp    0x7fff9836536c            ; -[NSObject(NSKeyValueObserverRegistration) addObserver:forKeyPath:options:context:] + 109
0x7fff983654df:  movq   %rax, %r14
0x7fff983654e2:  testb  %bl, %bl
0x7fff983654e4:  je     0x7fff983654fa            ; -[NSObject(NSKeyValueObserverRegistration) addObserver:forKeyPath:options:context:] + 507
0x7fff983654e6:  jmp    0x7fff983654f5            ; -[NSObject(NSKeyValueObserverRegistration) addObserver:forKeyPath:options:context:] + 502
0x7fff983654e8:  callq  0x7fff985d156a            ; symbol stub for: objc_exception_rethrow
0x7fff983654ed:  jmp    0x7fff98365390            ; -[NSObject(NSKeyValueObserverRegistration) addObserver:forKeyPath:options:context:] + 145
0x7fff983654f2:  movq   %rax, %r14
0x7fff983654f5:  callq  0x7fff985d155e            ; symbol stub for: objc_end_catch
0x7fff983654fa:  movq   %r14, %rdi
0x7fff983654fd:  callq  0x7fff985d2ac4            ; symbol stub for: _Unwind_Resume
0x7fff98365502:  callq  0x7fff985d15ee            ; symbol stub for: objc_terminate
0x7fff98365507:  nop    
0x7fff98365508:  nop    
0x7fff98365509:  nop    
0x7fff9836550a:  nop    
0x7fff9836550b:  nop    
0x7fff9836550c:  nop    
0x7fff9836550d:  nop    
0x7fff9836550e:  nop    
0x7fff9836550f:  nop    
0x7fff98365510:  nop    
0x7fff98365511:  nop    
0x7fff98365512:  nop    

1 个答案:

答案 0 :(得分:0)

我有完全相同的问题。对我来说,事实证明,问题不在被观察的物体中,而是在观察者身上。

在我的情况下,我有一个自定义MKAnnotationView正在观察我的其他财产。当注释视图离开地图时,它被缓存,使得无法访问消息。

我怀疑您的财产是通过类似的自定义视图观察的,也许是自定义UITableViewCell?我的解决方案是检查注释何时设置为值和nil,并在发生时添加或删除观察者。