2014년 10월 15일 수요일

#define

#define IS_IPAD    (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)

#define POINT(_INDEX_) [(NSValue *)[points objectAtIndex:_INDEX_] CGPointValue]

#define RADIANS_TO_DEGREES(radians) ((radians) * (180.0 / M_PI))

#define RGBACOLOR(r,g,b,a) [UIColor colorWithRed:r/255.f green:g/255.f blue:b/255.f alpha:a]

#define ColorWithHexa(rgbValue) [UIColor colorWithRed:((rgbValue & 0xFF0000) >> 16)/255.0 \
                                        green:((rgbValue & 0xFF00) >> 8)/255.0 \

                                        blue:(rgbValue & 0xFF)/255.0 alpha:1.0]; \

#define RESIZABLE(_VIEW_) [_VIEW_ setAutoresizingMask:UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth]

#define DEGREES_TO_RADIANS(angle) ((angle) / 180.0 * M_PI)
#define RADIANS_TO_DEGREES(radians) ((radians) * (180.0 / M_PI))

// check iOS version
#define SYSTEM_VERSION_EQUAL_TO(v)                  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v)              ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN(v)                 ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v)     ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)


#define DOCUMENTS_DIR ([NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject])
#define SCREEN_WIDTH ((([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortrait) || ([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortraitUpsideDown)) ? [[UIScreen mainScreen] bounds].size.width : [[UIScreen mainScreen] bounds].size.height)
#define SAFE_RELEASE(obj) ([obj release], obj = nil)
#define SAFE_TIMER_RELEASE(obj) ([obj invalidate]; [obj release]; obj = nil)
#define SAFE_ASSIGN(obj, expr) ([(expr) retain], [obj release], obj = (expr))

2014년 10월 9일 목요일

@ 매크로


1.
    NSString *string = @"<#string#>"

2.  
    id express = @(<#expression#>)

  (ex)
    NSInteger idx = 40;
    NSString *idxString = [@(idx) stringValue];

3.    
    NSArray *array =  @[<#objects, ...#>]

4.    
    @autoreleasepool {
        <#statements#>
    }

5.    
    char[] chars =  @encode(<#type-name#>)

6.    
    Protocol *protocol = @protocol(<#protocol-name#>)

7.    
    SEL sel = @selector(<#selector#>)

8.    
    @throw <#expression#>
    
9.
    NSDictonary *dic = @{<#key#>: <#object, ...#>}
    
10.
    @try {
        <#Code that can potentially throw an exception#>
    }
    @catch (NSException *exception) {
        <#Handle an exception thrown in the @try block#>
    }
    @finally {
        <#Code that gets executed whether or not an exception is thrown#>

    }

11. structure

    CGSize theSize = {
        .width = 100.f,
        .height = 100.f,
    };
    
    CGRect theRect = {
        {.x = 10.f, .y= 10.f},
        {.width = 200.f, .height = 200.f}
    };

2014년 10월 1일 수요일

UIAlertView & Block function

source

//
//  CustomUIAlertView.m
//  patternpie
//
//  Created by MYUNG GU KIM on 10/2/14.
//  Copyright (c) 2014 piestudio. All rights reserved.
//

#import "CustomUIAlertView.h"

@implementation CustomUIAlertView

- (void)showWithBlock:(void (^)(int selectedIndex))complete
{
    self.delegate = self;
    ptrComplete = complete;
    [self show];
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    ptrComplete((int)buttonIndex);
}


@end




header 

//
//  CustomUIAlertView.h
//  patternpie
//
//  Created by MYUNG GU KIM on 10/2/14.
//  Copyright (c) 2014 piestudio. All rights reserved.
//

#import <UIKit/UIKit.h>

void (^ptrComplete)(int);

@interface CustomUIAlertView : UIAlertView <UIAlertViewDelegate>
{
}
- ( void )showWithBlock: ( void ( ^ )( int selectedIndex) )complete;
@end





using


[[[CustomUIAlertView alloc] initWithTitle:nil message:@"Do you want Challenge?" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:@"Cancel", nil] showWithBlock:^(int selectedIndex) {
            NSLog(@"You selected button %d", selectedIndex);
        }];