Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 5. Classes and Objects > Creating Object Methods

Creating Object Methods

While you can execute a class method with just the name of the class, you need an object to be able to execute object methods—and object methods are more useful because class methods have restrictions on how they store data that object methods don’t. You define an object method in a class by preceding its prototype and definition with a minus sign, “-”, in both the @interface section and @implementation section, as shown here, where we create an object method named stringValue that returns a string:

@interface ClassWithMethod : NSObject
- (const char *) stringValue;
@end

@implementation ClassWithMethod
- (const char *) stringValue;
{
  return "Hello there.";
}
@end


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial