Skip to content

Latest commit

 

History

History
83 lines (64 loc) · 1.9 KB

objc.md

File metadata and controls

83 lines (64 loc) · 1.9 KB

Constants in Objective C

Declaring constants in Objective C (like public static string in java)

In .h

@interface NBoxLocationManager : NSObject
FOUNDATION_EXPORT NSString *const NBoxLocationUpdateNotification;
@end

In .m

#import "NBoxLocationManager.h"

@implementation NBoxLocationManager
NSString *const NBoxLocationUpdateNotification = @"NBoxLocationUpdateNotification";
@end

Singleton in Objective C

#import "NBoxLocationManager.h"

@interface NBoxLocationManager()
@property (nonatomic) CLLocationManager *locationManager;
@end

@implementation NBoxLocationManager

static BOOL initialized = NO;
static NBoxLocationManager *sharedSingleton;

// Designated method by which people should be accessing this singleton.
+ (id)sharedInstance
{
    return sharedSingleton;
}

// initialize is a class method, called for the first time class is loaded.
+ (void)initialize
{
    NSLog(@"NBoxLocationManager initialize %p", self);
    
    if(!initialized) {
        sharedSingleton = [[NBoxLocationManager alloc] init];
        initialized = YES;
    }
}

// "private" init, designed to be called from initialize, and only once.
- (instancetype)init
{
    self = [super init];
    NSLog(@"NBoxLocationManager init %p", self);

    if(initialized) {
        [NSException raise:@"NBoxLocationManager reinitialized" format:@"NBoxLocationManager should be obtained with +initialize"];
    }
    
    self.locationManager = [[CLLocationManager alloc] init];
    
    // ...
    // rest goes here
    // ...
}

Method not implemented

- (void)performWithAsset:(AVAsset*)asset
{
	[self doesNotRecognizeSelector:_cmd];
}

For reference see AVSimpleEditor_AVSECommand_m

Throw Exception

[NSException raise:@"Invalid foo value" format:@"foo of %d is invalid", foo];