01.02.2014 Views

Objective-C Fundamentals

Objective-C Fundamentals

Objective-C Fundamentals

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

250 CHAPTER 12 Reading and writing application data<br />

NSManagedObject subclass from the iOS > Core Data section.<br />

Click Next and select the PocketTasks data model.<br />

Click Next again and put a checkmark next to Person and<br />

Task (see figure 12.6).<br />

Finally, click Finish.<br />

Build and run the application. Your project should still<br />

work just as before.<br />

When you examine the source files for the Person and<br />

the Task classes, you’ll find accessors for your properties<br />

and relationships. Let’s add one method to the Person<br />

class. Open Person.h and add this line:<br />

@property (readonly) NSString *fullName;<br />

Next, open Person.m and add the implementation:<br />

- (NSString *)fullName {<br />

return [NSString stringWithFormat:@"%@ %@",<br />

self.firstName, self.lastName];<br />

}<br />

Now you have the code to put together the full name in a<br />

Figure 12.5 Tasks can be<br />

added and marked as done by<br />

single place: in the model. You can see why it almost always<br />

tapping on them. Completed<br />

makes sense to work with these NSManagedObject subclasses<br />

in your Core Data project: it’s easier to access the the right.<br />

tasks have a checkmark on<br />

properties and relationships, it gives you the opportunity to<br />

add custom logic to your models, and it makes the code easier to read and maintain.<br />

Figure 12.6 Xcode can automatically generate <strong>Objective</strong>-C classes for the entities<br />

in a data model.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!