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
  • PrintPrint
Share this Page URL
Help

Chapter 5. Classes and Objects > Using Class Methods

Using Class Methods

A class method is a method you can execute using just the class name—no object is required. You define class methods with a plus sign, “+”, in front of their names in both the class’s @interface section and @implementation section, as shown here, where a class returns some text:

#include <stdio.h>
#include <Foundation/Foundation.h>

@interface Container
+ (const char *) classMethod;
@end

@implementation Container
+ (const char *) classMethod
{
  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


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint