Chapter 14. Getting Data from Other Objects

In This Chapter

  • Getting the data an object needs for another object

  • Understanding how declared properties work

  • Getting how the compiler synthesizes accessors

  • Recognizing the impact of declared properties to your program

  • Using accessors

  • Knowing the best way to use declared properties and accessors

In Chapter 11, you factor your code to create a Destination object that manages the other objects you needed in your model. You see how the Destination object can use other objects by sending them messages. While most of those messages are to get an object to do something (spendDollars:, for example), as you see when you implement returnBalance in Budget and leftToSpend in Destination, some of these messages are about data.

That data returned by those methods is stored as instance variables, but as you know, one object can't and shouldn't access another object's instance variables directly (hence, the need for those two methods). In this chapter, I will show you another way to get data from an object — declared properties — and I'll also tell you about some things you need to handle with care.

Getting Data from Objects

As I refine the Vacation application, I need to start thinking more about the practical aspects of using this application, especially as I march down the road toward putting on a user interface.

One thing that strikes me is that this whole exchange rate thing is not very robust. After all, the exchange rate changes often during the day, so ...

Get Objective-C® For Dummies® now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.