[swift-users] Binding NSTextField value to NSNumber

Etan Kissling kissling at oberon.ch
Wed Jan 6 13:25:05 CST 2016


Hey there,

I have a model that contains an optional NSNumber.

@objc(Model) final class Model : NSObject {
    dynamic var someNumber: NSNumber?
}


I now bind such en object to an NSObjectController,
and bind the value binding of an NSTextField to the object controller's selection.someNumber key path.


After loading, the number is properly displayed.

(lldb) e/x someNumber!
(__NSCFNumber *) $R0 = 0x0000000000002a57

(lldb) e/d someNumber!.intValue
(Int32) $R1 = 42


However, when I change the entry, the number is replaced by a string.

(lldb) e/x someNumber!
(NSTaggedPointerString *) $R2 = 0x0000000000323425 "42"

(lldb) e/d someNumber!.intValue
(Int32) $R3 = 42

Now, stuff like ==, isEqualToNumber, and compare obviously no longer works.
-[NSTaggedPointerString isEqualToNumber:]: unrecognized selector sent to instance 0x303425



It seems like the NSNumber variable morphed into a NSString.




What's going on here?



Etan




PS: The NSTextField documentation clearly states that NSNumbers are supported to be bound as the value:

value
An NSString or NSNumber that is displayed as the content of the NSTextField.

Availability:
Available in OS X v10.3 and later.














-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160106/80c424ff/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160106/80c424ff/attachment.sig>


More information about the swift-users mailing list