Core Data rocks. If there are good reasons to build data objects manually, I have not yet seen them. I’ll give the NSTextField instructions in brackets because they’re just so close.
Contents
Context
The problem I – and several other users – ran into is that it’s straightforward to bind an NSTextField to a Core Data entity, but not the more flexible NSTextView.
Abstract Explanation
An NSTextField displays objects of type NSString. If you want to bind it to a Core Data entity, you set that entity to be of type ‘String’. An NSTextView can display different types of data – the very attraction is that you can display images and text mixed together – which means that it contains objects of type NSData and you need to set the type to ‘Binary data’.
That’s all.
Data Model
Anything you want to be displayed in, and bound to, an NSTextView needs to have its type set to ‘Binary data’. (For NSTextField, use ‘String’)
Interface Builder
Create an NSArrayController. In the ‘Attributes’ tab, set ‘Mode’ to ‘Entity‘ and make sure 'automatically prepares content' is checked.
In the ‘Bindings’ tab, bind the managedObjectContext to the App Delegate’s managedObjectContext
Create an NSTextView. (Make sure you select the NSTextView rather than the surrounding scroll view). In the Inspector’s ‘Bindings’ tab, bind its data to your NSArrayController and set the model Key Path to the entity you wish to display. If your entity is set to ‘string’ it will throw an exception, so make sure it’s of type ‘binary data’.
Linkage
(to be implemented)
Antidotes
none
Entanglements
- Core Data
- Text Attributes
Areas
- Core Data
- Bindings
- Text handling