Skip to Content
iOS 7 Programming Fundamentals
book

iOS 7 Programming Fundamentals

by Matt Neuburg
October 2013
Beginner content levelBeginner
422 pages
12h 35m
English
O'Reilly Media, Inc.
Content preview from iOS 7 Programming Fundamentals

Chapter 5. Objective-C Instances

Instances are the heart of the action in an Objective-C program. Obtaining and manipulating instances will be crucial to just about everything you do. Nearly every line of code that you write will be concerned with one or more of these activities:

  • Referring to an instance that already exists
  • Creating a new instance that didn’t exist previously
  • Assigning an instance to a variable
  • Sending a message to an instance
  • Passing an instance as an argument in a method call

How Instances Are Created

Your class objects are created for you automatically as your program starts up, but instances must be created individually as the program runs. Ultimately, every instance comes into existence in just one way: someone asks a class to instantiate itself (see Chapter 4). But there are three different ways in which this can occur: ready-made instances, instantiation from scratch, and nib-based instantiation.

Ready-Made Instances

One way to create an instance is indirectly, by calling code that does the instantiation for you. You can think of an instance obtained in this indirect manner as a “ready-made instance.” (That’s my made-up phrase, not an official technical term.) Consider this simple code:

NSString* s2 = [s uppercaseString];

The documentation for the NSString instance method uppercaseString says that it returns “a string with each character from the receiver changed to its corresponding uppercase value.” In other words, you send the uppercaseString message ...

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.
Start your free trial

You might also like

iOS 7 Programming Cookbook

iOS 7 Programming Cookbook

Vandad Nahavandipoor
Programming iOS 11

Programming iOS 11

Matt Neuburg
Programming iOS 12

Programming iOS 12

Matt Neuburg

Publisher Resources

ISBN: 9781491946039Errata PageSupplemental Content