Binding an NSNumber to an NSTableColumn - MacRumors Forums
Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Dec 25, 2012, 04:14 PM   #1
BadWolf13
macrumors 6502
 
Join Date: Dec 2009
Binding an NSNumber to an NSTableColumn

Hi, not sure what I'm doing wrong, or if this just isn't supposed to be done, but I'm having issues binding the value of an NSTablecolumn to an NSNumber through an Array Controller. When the document loads, it displays the values in the table properly, but whenever I try to select a row in this table, it crashes with EXC_BAD_ACCESS.

Now I tried changing the Key Path in the bindings window of the table column to add ".doubleValue", whereby I can select the row without it crashing, but then it changes all the numbers on that row to 0.

Another table view in the same app has NSUInteger and double values, and that one works ok, it's just when there's an NSNumber involved that it crashes. Are we not supposed to use NSNumbers for binding table columns? It seems like Apple is encouraging us to stop using primitives, so I find that highly unlikely. Anyone got any thoughts?
BadWolf13 is offline   0 Reply With Quote
Old Dec 26, 2012, 04:58 AM   #2
gnasher729
macrumors G5
 
gnasher729's Avatar
 
Join Date: Nov 2005
Quote:
Originally Posted by BadWolf13 View Post
Hi, not sure what I'm doing wrong, or if this just isn't supposed to be done, but I'm having issues binding the value of an NSTablecolumn to an NSNumber through an Array Controller. When the document loads, it displays the values in the table properly, but whenever I try to select a row in this table, it crashes with EXC_BAD_ACCESS.

Now I tried changing the Key Path in the bindings window of the table column to add ".doubleValue", whereby I can select the row without it crashing, but then it changes all the numbers on that row to 0.

Another table view in the same app has NSUInteger and double values, and that one works ok, it's just when there's an NSNumber involved that it crashes. Are we not supposed to use NSNumbers for binding table columns? It seems like Apple is encouraging us to stop using primitives, so I find that highly unlikely. Anyone got any thoughts?
1. Don't feel in any way encouraged to avoid primitives. Primitives (like double or int vs. NSNumber) are orders of magnitude faster to use, and a lot easier to use. The only reason to use NSNumber is in situations where objects are needed for whatever reason - for example to put things into dictionaries - which have the advantage to a struct that they are flexible and adaptable without code changes.

2. If an NSNumber "crashes" the reason is most likely that it has been released. For example [[NSNumber numberWithInteger:3000] will be an autoreleased object that gets destroyed when its autorelease pool goes away. (Except that in some cases it won't crash, which makes the problem harder to detect).
gnasher729 is offline   0 Reply With Quote
Old Dec 26, 2012, 12:29 PM   #3
BadWolf13
Thread Starter
macrumors 6502
 
Join Date: Dec 2009
What about bindings and KVO? I was under the impression that they work better with objects than with primitives?

For instance, this application, whenever the user changes the value in a text field, I want the filter predicate on an array controller to update automatically. Is this gonna work just as well if I bind my text field to a double, as opposed to an NSNumber?
BadWolf13 is offline   0 Reply With Quote
Old Dec 26, 2012, 04:42 PM   #4
Sydde
macrumors 68000
 
Sydde's Avatar
 
Join Date: Aug 2009
KVO works just fine with primitives it is triggered by a setter function (which notifies to observer). If your array elements are compound objects, as they often are for tables, you can have KVC primitives no problem at all.
__________________
You got to be a spirit. You can't be no ghost.
Sydde is online now   0 Reply With Quote
Old Dec 30, 2012, 03:49 AM   #5
jeanlain
macrumors 6502
 
Join Date: Mar 2009
NSNumber should bind to a column's value just fine. You can use an NSNumber formatter in the table cell if you want.
I think your crash reflect another issue with an NSNumber object being deallocated while it still shows in the table. You can enable zombies in the run settings to see if messages are sent to deallocated instances.
jeanlain is online now   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Looking for OD only binding script / need help with binding to OD with DPS dabizkitman Mac OS X Server, Xserve, and Networking 5 Jan 9, 2014 10:29 AM
Need help with binding some keys in windows 7! Zeov Windows, Linux & Others on the Mac 0 Jul 6, 2013 04:29 PM
How to select NSNumber data with NSPredicate?? mikezang iPhone/iPad Programming 0 Oct 17, 2012 09:39 AM
AD Binding Issue dmoore70 MacBook Pro 4 Aug 28, 2012 03:53 PM

Forum Jump

All times are GMT -5. The time now is 09:14 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC