Game Development Reference
In-Depth Information
in a class. At times you will find it helpful to define a set of related methods that are
independent of a specific class.
Objective-C provides protocols that are used to define a group of related methods;
either optional or required. Any class can use a protocol, which means that it requires
implementations for all of the methods in the protocol.
Values and collections
In addition to primitive types defined by the C language, such as int, float or char,
Objective-C can also use Cocoa or Cocoa Touch classes to represent values. These
classes include:
• Strings of characters are defined with NSString
• Different types of numbers use the NSNumber class
• The NSValue class for other values such as C structures.
Collections are generally represented as instances of one of the collection classes,
such as NSArray , NSSet or NSDictionary , which are used to collect other
Objective-C objects.
Blocks
In C, Objective-C, and C++, blocks are a feature that represent a unit of work; which
makes them similar to closures in other programming languages. They include a
block of code along with a captured state, blocks can be used to simplify common
tasks such as:
• Collection enumeration
• Sorting
• Testing
• Concurrent or asynchronous schedule tasks
Error Objects: Cocoa and Cocoa Touch handles programming errors, which need to
be fixed before an app is submitted to the App Store.
All other errors are represented by instances of the NSError class. Be sure to plan
for errors and decide how best to handle them in such a way that does not negatively
impact the user experience.
Search WWH ::




Custom Search