Appcode base snippets live templates - PaulTaykalo/AppCode-Settings GitHub Wiki

a

Async in main Queue

dispatch_async(dispatch_get_main_queue(), ^{
  $SELECTION$
});

addtarget

Adds target tobutton

[$TYPE$ addTarget:self action:@selector($SELECTOR$) forControlEvents:UIControlEventTouchUpInside];

alloc

Insert alloc and init

[[$TYPE$ alloc] $METHOD$]$END$

animate

animate with UIView block

    [UIView animateWithDuration:$DURATION$ 
                     animations:^{
                       $SELECTION$
                     }
       ];

animate_with_completion

animate with UIView block

    [UIView animateWithDuration:$DURATION$ 
                     animations:^{
                       $SELECTION$
                     }
                     completion:^(BOOL completed) {
                       $CURSOR$
                     }
       ];

app

Application

[UIApplication sharedApplication]

buttbi

Button background image

[$BUTTON$ setBackgroundImage:[UIImage imageNamed:@"$NAME$"] forState:UIControlStateNormal];
[$BUTTON$ setBackgroundImage:[UIImage imageNamed:@"$NAME$-highlighted"] forState:UIControlStateHighlighted];
[$BUTTON$ setBackgroundImage:[UIImage imageNamed:@"$NAME$-selected"] forState:UIControlStateSelected];

butti

Button image

[$BUTTON$ setImage:[UIImage imageNamed:@"$NAME$"] forState:UIControlStateNormal];
[$BUTTON$ setImage:[UIImage imageNamed:@"$NAME$-highlighted"] forState:UIControlStateHighlighted];
[$BUTTON$ setImage:[UIImage imageNamed:@"$NAME$-selected"] forState:UIControlStateSelected];

conforms

conformsToProtocol

if ([$VAR$ conformsToProtocol:@protocol($PROTOCOL$)]) {
  id<$PROTOCOL_COPY$> $NEW_VAR$ = (id<$PROTOCOL_COPY$>)$VAR_COPY$;
  $END$
}

defblock

TypeDef block

typedef $TYPE$ (^$NAME$)($PARAMS$);

desc

Generates one item for class description method

[description appendFormat:@"$NAME$ = %$TYPE$, ", _$NAME$];

descr

Generates class description method

- (NSString *)description {
   NSMutableString * description = [NSMutableString string];
   [description appendFormat:@"<%@ %0x", NSStringFromClass([self class]), self];

   [description appendFormat:@">"];
   return description;
}

dma

Mutable Array creation

NSMutableArray * $MA$ = [NSMutableArray array];

dmd

Mutable Dictionary Creation

NSMutableDictionary * $NAME$ = [NSMutableDictionary dictionary];

dms

Mutable String creation

NSMutableString * $MA$ = [NSMutableString string];

each

Iterate a collection

for ($ITEM_TYPE$ $VAR$ in $COLLECTION$) {
  $END$
}

fm

File Manager

NSFileManager * fileManager = [NSFileManager defaultManager];
$CURSOR$

for

Indexed for(;;) loop

for (int $INDEX$ = 0; $COPY_INDEX$ < $UPPER_BOUND$; $COPY_INDEX$++) {
$END$
}

ibac

-(IBAction)message:(id)sender

-(IBAction)$MESSAGE$:(id)sender$END$

ifce

Extension class declaration

@interface $CLASSNAME$ ()

$END$

@end

img

Image!

[UIImage imageNamed:@"$IMAGE_NAME$"]

imgw

Image view with image named

UIImageView * $IMAGENAME$ = [UIImageView alloc] initWithImage:[UIImage imageNamed:@"$NAME$"](/PaulTaykalo/AppCode-Settings/wiki/UIImageView-alloc]-initWithImage:[UIImage-imageNamed:@"$NAME$");

imgws

Image view with strerchable image

UIImageView * $IMAGENAME$ = [UIImageView alloc] initWithImage:[[UIImage imageNamed:@"$NAME$"] stretchableImageWithLeftCapWidth:$LEFT$ topCapHeight:$TOP$](/PaulTaykalo/AppCode-Settings/wiki/UIImageView-alloc]-initWithImage:[[UIImage-imageNamed:@"$NAME$"]-stretchableImageWithLeftCapWidth:$LEFT$-topCapHeight:$TOP$);

kind

isKindOfClass

if ([$VAR$ isKindOfClass: [$CLASS$ class]]) {
  $CLASS_COPY$ *$NEW_VAR$ = ($CLASS_COPY$*)$VAR_COPY$;
  $END$
}

l

Wrapping selection with nsLog

NSLog(@"$SELECTION$ = %$TYPE$", $SELECTION$);

label

Label creation

UILabel * label = [UILabel new];

labelb

Create label with block format

({
   UILabel * label = [[UILabel alloc] init];
   $END$
   label;
});

loc

Insert a NSLocalizedString call

NSLocalizedString($KEY$, @"$COMMENT$")$END$

loct

Insert a NSLocalizedString call

NSLocalizedStringFromTable($KEY$, @"$TABLE$",@"$COMMENT$")$END$

log

Insert new NSLog call

NSLog(@"$END$");

logm

Log current function/method

NSLog(@"%s", $CONTEXT$);$END$

logs

SFCLog

SFCLog($TOKEN$, "$FORMAT$");

logv

Log expression value

NSLog(@"$EXPR_COPY$ = $FORMAT$", $EXPR$);$END$

ma

Mutable array as array

[NSMutableArray array]

md

Mutable Dictionary

NSMutableDictionary * $DICTIONARYNAME$ = [NSMutableDictionary dictionary];

ms

Mutable string

[NSMutableString string]

nc

Notification Center

NSNotificationCenter * notificationCenter = [NSNotificationCenter defaultCenter];

new

Creates new instance of some class

$CLASS$ * $VARIABLE$ = [$CLASS$ new];

objc_assoc

Adds Getter/Setter associated object

static char * _$objectTag$Key = "$objectTag$";

- (id)$objectTag$ {
    return objc_getAssociatedObject(self, _$objectTag$Key);
}

- (void)set$setterObjectTag$:(id)$objectTag$ {
    objc_setAssociatedObject(self, _$objectTag$Key, $objectTag$, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

pm

#pragma mark

#pragma mark - $END$

pool

New release pool

NSAutoreleasePool *pool = [NSAutoreleasePool new];
$END$
[pool drain];

propa

@property (assign)

@property (nonatomic, assign) $DECLARATION$;$END$

propc

@property (copy)

@property (nonatomic, copy) $DECLARATION$;$END$

propr

@property (retain)

@property (nonatomic, retain) $DECLARATION$;$END$

propro

@property (readonly)

@property (nonatomic,readonly) $DECLARATION$;$END$

props

@property (strong)

@property (nonatomic, strong) $DECLARATION$;$END$

propw

@property (weak)

@property (nonatomic, weak) $DECLARATION$;$END$

reason

Adds one reason why do I like Appcode

NSLog(@"Reason #$REASON_NUMBER$ : $END$"); 

s

String with format wrap

[NSString stringWithFormat:$SELECTION$]$END$

str

String

NSString * $NAME$ = $VALUE$;

sub

All subviews iterations

for (UIView * subview in [$VIEW$ subviews]) {
    $END$        
}

swf

String with format expression

[NSString stringWithFormat:@"%$TYPE$", $VARIABLE$]$END$

syn

@synthesize

@synthesize $PROPERTY_NAME$ = _$PROPERTY_NAME$;$END$

sz

String form Size

NSStringFromCGSize($VAR$)

ud

User defaults

NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];

uilabel

Creates UILabel

UILabel * $LABEL_NAME$ = [UILabel new];
$LABEL_NAME$.text = $TEXT$;
[$LABEL_NAME$ sizeToFit];

[$VIEW$ addSubview:$LABEL_NAME$];


vc

viewController

$ViewController$ * $ViewControllerName$ = [$ViewController$ $initMethod$];

view

Debug view

UIView * $view$ = [UIView new];
[$view_copy$ setBackgroundColor:[UIColor redColor]];
[$view_copy$ setFrame:$END$];

vlc

Pragma for View Lifecycle

#pragma mark - View Lifecycle

warning-retain-cycle

pragma block with suppressing retain cycle

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-retain-cycles"
$SELECTION$
#pragma clang diagnostic pop

weakify

Wekifies selection (Used for variables)

__weak int weak$SELECTION2$ = $SELECTION$;