Skip to Content
Programming iOS 4
book

Programming iOS 4

by Matt Neuburg
May 2011
Beginner
834 pages
25h 19m
English
O'Reilly Media, Inc.
Content preview from Programming iOS 4

Properties

A property (see Chapter 5) is syntactic sugar for calling an accessor by using dot-notation. An object does not have a property unless its class (or that class’s superclass, of course) declares it. For instance, in a earlier example we had an object with an NSMutableArray instance variable and a setter, which we called like this:

[self setTheData: d];

If this object’s class code declares a property theData, we could instead say:

self.theData = d;

The effect would be exactly the same, because setting a property is just a shorthand for calling the setter. Similarly, suppose we were to say this:

NSMutableArray* arr = self.theData;

That is exactly the same as calling the getter.

Properties offer certain advantages that accessors, of themselves, do not:

  • It is simpler to declare one property than to declare two accessor methods.
  • A property declaration includes a statement of the setter’s memory management policy. Thus it easy to know, just by glancing at a property declaration, how the incoming value will be treated. You could find this out otherwise only by looking at the setter’s code — which, if this is a built-in Cocoa type, you cannot do (and even in the case of your own code, it’s a pain having to locate and consult the setter directly).
  • With a property declaration, you can ask Cocoa to construct the accessors for you, automatically. Such an automatically constructed accessor is called a synthesized accessor. Writing accessors is boring and error-prone; with a property, you ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Programming iOS 9

Programming iOS 9

Matt Neuburg
Programming iOS 13

Programming iOS 13

Matt Neuburg

Publisher Resources

ISBN: 9781449397302Errata