XCode/Objective-C 雑記

要整理

http://developer.apple.com/jp/documentation/Cocoa/Conceptual/ObjectiveC/ObjC.pdf

  • .m は C + objc, .mm は C++ + objc
  • object 識別子は id
  • isa フィールドで introspection
  • [receiver message]
  • [myRect setOrigin:30.0 :50.0];
  • [myRect setWidth:10.0 height:15.0];
  • [receiver makeGroup:group, memberOne, memberTwo, memberThree];
  • [myRect setPrimaryColor:[otherRect primaryColor]];
  • id aClass = [anObject class];
  • Class aClass = [anObject class];
  • init

id myRect;

myRect = [Rectangle alloc];

myRect = [[Rectangle alloc] init];

  • if ( [anObject isKindOfClass:[Rectangle class]] )
  • class def

@interface ClassName :ItsSuperclass

{

instance variable declarations

}

method declarations

@end

  • instance vars

float width;

float height;

BOOL filled;

NSColor *fillColor;

  • class method
  1. alloc;
  • instance method

- (void)display;
- (void)setRadius:(float)aRadius;

  • if type is missing, it is treated as 'id'
  • var args

- makeGroup:group, ...;

  • use import instead of include. import includes the source only once.

#import "Rectangle.h"

  • tell compiler that the source uses classes outside of class hierarchy

@class Rectangle, Circle;

  • class implementation

@implementation ClassName :ItsSuperclass

{

instance variable declarations // can be omitted

}

method definitions

@end

  • -

#import "ClassName.h"

@implementation ClassName

method definitions

@end

    • -
  1. alloc

{

...

}

  • (BOOL)isfilled

{

...

}

  • (void)setFilled:(BOOL)flag

{

...

}

    • -

@interface Worker :NSObject

{

char *name;

@private

int age;

char *evaluation;

@protected

id job;

float wage;

@public

id boss;

}

    • -
  • NSString literal @"..."
  • Icon Composer
  • info.plist
  • nib のローカライズ, menu, window title, etc
  • application name localize
  • infoPlist.strings

CFBundleName=電卓
CFBundleDisplayName=
info.plist に LSHaslocalizedDisplayName=yes
LSHaslocalizedDisplayName

localize しない場合は info.plist に設定

  • debug image vs release image pjoject -> active release type

derug runs only on dev machines

    • -

NSDocument
NSWindowController