objective c

Objective-C Cheat Sheet by Alex Gordon (alextgordon) via cheatography.com/425/cs/198/ Class Interfaces Class Implementa...

0 downloads 77 Views 33KB Size
Objective-C Cheat Sheet by Alex Gordon (alextgordon) via cheatography.com/425/cs/198/ Class Interfaces

Class Implementation

Class Use

@interface Shape : NSObject

@implementation Shape

- (void)drawRect:(NSRect)rect {

@property (assign) NSPoint center;

@synthesize centre;

rect = [self bounds];

@property (strong) NSColor* color;

@synthesize color;

[[NSColor cyanColor] set];

@end

- (void)draw {

[NSBezierPath fillRect:rect];

[color set]; @interface Rectangle : Shape

}

Rectangle* rectangle = [[Rectangle alloc] init];

@property (assign) NSSize size;

@end

rectangle.size = NSMakeSize(300, 200);

@end

rectangle.centre = NSMakePoint(NSMidX(rect), @implementation Rectangle

@interface Circle : Shape

@synthesize size;

@property (assign) CGFloat radius;

- (void)draw {

@end

[super draw]; [NSBezierPath fillRect:NSMakeRect(self.centre.x -

NSMidY(rect)); rectangle.color = [NSColor whiteColor]; [rectangle draw];

Circle* circle = [[Circle alloc] init];

size.width / 2, self.centre.y - size.height / 2, size.w

circle.radius = 60;

idth, size.height)];

circle.centre = rectangle.centre;

}

circle.color = [NSColor redColor];

@end

[circle draw]; }

@implementation Circle @synthesize radius;

Result

- (void)draw {

http://chocolatapp.com/snaps/japanflag.png

[super draw]; [[NSBezierPath bezierPathWithOvalInRect:NSMak eRect(self.centre.x - radius, self.centre.y - radius, radius2, radius2)] fill]; } @end Cheatographer

Cheat Sheet

Sponsor

Alex Gordon (alextgordon)

This cheat sheet was published on 10th January,

Envoy, for simple and effective bug management.

cheatography.com/alextgordon/

2012 and was last updated on 10th January, 2012.

Try it free!

chocolatapp.com

http://www.envoyapp.com