1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
|
#import "Somefile.h"
@implementation ABC
- (id) a: (A)a
b: (B)b
c: (C)c... {
// ternary expressions and message passing
a = b ? c : d;
[a b: c ? d : e];
a ? [b c: d] + e : f;
[a b];
[[a b: c] d];
label:
[a b:c
d:e];
other_label:
return 1;
YES @YES NO @NO nil true @true false @false;
}
@end
@implementation ABC
- (void)xyz;
@end
@autoreleasepool {
NSString *string = [[NSString alloc] initWithUTF8String:"I will be autoreleased"];
}
double (^multiplyTwoValues)(double, double) = ^(double firstValue, double secondValue) {
return firstValue * secondValue;
};
void (^simpleBlock)(void) = ^{
NSLog(@"This is a block");
};
- foo:(id) foo {
[self bar:foo];
}
[[SomeClass] inlineBlock:(^NSString *){
NSString *var = @"blah";
return var;
}];
NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:
@"quattuor", @"four", @"quinque", @"five", @"sex", @"six", nil];
NSString *key;
for (key in dictionary) {
NSLog(@"English: %@, Latin: %@", key, [dictionary valueForKey:key]);
}
NSDictionary *literalDict = @{
@"name" : NSUserName(),
@"date" : [NSDate date],
@"processInfo" : [NSProcessInfo processInfo]
};
NSArray *literalArray = @[ @"Hello", NSApp, [NSNumber numberWithInt:42] ];
// MyClass.h
@import Foundation;
@interface MyClass : NSObject
{
NSString *value;
NSTextField *textField;
@private
NSDate *lastModifiedDate;
}
@property(copy, readwrite) NSString *value;
@property(retain) IBOutlet NSTextField *textField;
@end
// To look up: are these comma-delimited?
// interface definition for a category
@interface Foo (Bar, Baz, Zot) {
}
// MyClass.m
// Class extension to declare private property
@interface MyClass ()
@property(retain) NSDate *lastModifiedDate;
@end
@implementation MyClass
@synthesize value;
@synthesize textField;
@synthesize lastModifiedDate;
// implementation continues
@end
@class myProtocols;
@protocol myProtocol1 <NSObject>
// list of methods and properties
doStuff:(float) myValue;
@end
@protocol myProtocol2 <NSObject>
// list of methods and properties
doOtherStuff:(float) myValue2 andText:(NSString *)myText andType:(NSString *)myType;
@end
@interface myProtocols:NSObject
{
__unsafe_unretained id <myProtocol1> _myDelegate1;
__unsafe_unretained id <myProtocol2> _myDelegate2;
}
@property (nonatomic, assign) id <myProtocol1> myDelegate1;
@property (nonatomic, assign) id <myProtocol2> myDelegate2;
@end
#import myProtocols.h
@implementation myProtocols
@synthesize myDelegate1 = _myDelegate1
@synthesize myDelegate2 = _myDelegate2
if ([_myDelegate1 respondsToSelector:@selector(doStuff:)])
[_myDelegate1 doStuff:3.5];
if ([_myDelegate2 respondsToSelector:@selector(doOtherStuff:andText:andType:)])
[_myDelegate2 doOtherStuff:4.5 andText:@"YES MAN" andType:@"YES BRO"];
@end
#import "myProtocols.h"
@interface classA: UIViewController <myProtocol1>
@property(strong, nonatomic) myProtocols *myProtoVC;
@end
#import "classA.h"
@interface classA ()
@end
@implementation classA
- (void)viewDidLoad
{
[super viewDidLoad];
_myProtoVC = [[myProtocols alloc] init];
_myProtoVC.myDelegate1 = self;
}
-(void) doStuff:(float) myValue
{
NSLog(@" YES VALUE IS %f",myValue);
}
#import "myProtocols.h"
@interface classB: UIViewController <myProtocol2>
@property(strong, nonatomic) myProtocols *myProtoVC;
@end
#import "classB.h"
@interface classB ()
@end
@implementation classB
- (void)viewDidLoad
{
[super viewDidLoad];
_myProtoVC = [[myProtocols alloc] init];
_myProtoVC.myDelegate2 = self;
}
-(void) doOtherStuff:(float) myValue2 andText:(NSString *)myText andType:(NSString *)myType;
{
NSLog(@" YES VALUE IS %f and text %@ and type %@",myValue2,myText,myType);
}end
@interface HUDView (SubclassingHooks)
- (void)updatePageLabelFrameAnimated:(BOOL)animated;
- (void)updateThumbnailBarFrameAnimated:(BOOL)animated;
- (void)updateScrubberBarFrameAnimated:(BOOL)animated;
@end
ViewController *controller = [[ViewController alloc] initWithDocument:document configuration:[Configuration configurationWithBuilder:^(ConfigurationBuilder *builder) {
builder.thumbnailBarMode = ThumbnailBarModeScrollable;
builder.pageLabelEnabled = NO;
}]];
// Invalid Objective-C keyword
@FOO
|