small medium large xlarge

Back to: All Forums  Core Data
Generic-user-small
26 Sep 2009, 08:40
Wojciech Rolecki (3 posts)

I’ve encountered the problem before (when going through simple Core Data tutorials) and was hoping I’d find an explanation in the book.

Basically when editing an NSTableView column which is bound to Core Data attribute of type other than string, I always get the following entry in the console:

2008-11-05 17:20:12.578 recipes[13608:10b] Unacceptable type of value for attribute: property = “serves”; desired type = NSNumber; given type = NSCFString; value = 2.

Same goes for text fields bound to integer CD attributes.

Generic-user-small
26 Sep 2009, 08:41
Wojciech Rolecki (3 posts)

OK, I know that it requires some sort of NSFormatter. But why the hell no one mentions it? :-)

Avatarsmall_pragsmall
08 Nov 2008, 17:32
Marcus S. Zarra (284 posts)

Probably because that is really not an issue with Core Data :) That is expected/assumed in any editing of a NSTableView even if the data behind it is stored in something other than Core Data.

But for clarity, yes, if you are going to display date or number data in a column of a NSTableView it is best to put a NSFormatter on the column.

Johnjoyce_halo_pragsmall
08 Nov 2008, 23:27
John Joyce (9 posts)

I think the book should cover the NSFormatter, or at least instruct readers to put it in there. Without this, there will be many lost people. It’s going to be tough to gloss over anything with this.

Generic-user-small
15 Nov 2008, 11:59
Jamie Knight (1 post)

I had some trouble with this - all numeric fields refused to submit values and I couldn’t focus away from them until I had added an NSFormatter to each one. It’s okay for someone used to Cocoa, but as a seasoned programmer fairly new to it I was hunting around in all the wrong places trying to fix this. I agree with John Joyce, the instructions ought to mention it really.

Generic-user-small
15 Nov 2008, 16:25
Wojciech Rolecki (3 posts)

I also think that the book at least should hint about NSFormatter usage. If one’s that tough that implements his own NSTableView for CD usage, he’ll figure it out how to use them, but without any clue what’s going on, it’s tough. ;-)

Avatarsmall_pragsmall
19 Nov 2008, 16:47
Marcus S. Zarra (284 posts)

Thank you for all of the input. You can expect to see some discussion on this topic in the bindings chapter that I am polishing now :)

Generic-user-small
17 Apr 2009, 13:37
Duncan Groenewald (12 posts)

Hi, I just posted a query that is similar regarding how to bind a NSTextView field to a Core Data string attribute for storing formatted text.

Would be great if you could include something about how to do this and also how to still be able to do searches on the plain text stored in the database.

Not sure how one would do this but if necessary I would simply store two fields in the database, one with just the plain text and another with the formatted text. Of course I am assuming I can get a copy of the plain text from the NSTextView object - I am new to Cocoa so have yet to read up to see if the class supports this.

Avatarsmall_pragsmall
27 Jul 2009, 06:01
Marcus S. Zarra (284 posts)

Formatted text cannot be stored in a normal string attribute in a core data entity. You would need to use a transformable attribute instead. Also, you are nearly correct on the searchable solution. You store the text twice, once as a transformable and once as a flat string. In addition, the flat string should also strip out any non-ascii characters to speed up the searching and it should be indexed.

Once you have a transformable attribute set up you can then override its setter implementation (which is discussed in the book) and set the flat string whenever the transformable attribute is set.

You must be logged in to comment