O'Reilly logo

Mastering Swift 4 - Fourth Edition by Jon Hoffman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The Messages Objective-C class

The Messages Objective-C class will contain an array of messages and will expose one method named getMessage, which will return one randomly picked message from the array.

The following code shows the Messages header file:

#import <Foundation/Foundation.h> 
 
@interface Messages : NSObject 
 
-(NSString *)getMessage; 
@end 

In this header file, we expose one method named getMessage, which will return a message when called. The following code shows the implementation file for the Messages class:

#import "Messages.h" @implementation Messages NSMutableArray *theMessages; -(id)init { if ( self = [super init] ) { theMessages = [NSMutableArray new]; [theMessages addObject:@"You should learn from your mistakes"]; [theMessages ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required