/iOS-Code-Snippets

List of code snippets for iOS developers.

iOS-Code-Snippets

List of code snippets for iOS developers.

Table of Contents generated with DocToc

Debugging

Log

#define NSLog(__FORMAT__, ...) NSLog((@"[%@] [Line %d] -> " __FORMAT__), [[NSString stringWithUTF8String:__FILE__] lastPathComponent] , __LINE__, ##__VA_ARGS__)

Alert

#define DebugAlert(__FORMAT__, ...)  { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"Debug Message"] message:[NSString stringWithFormat:@"[%@] \n [Line %d] \n" __FORMAT__, [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __LINE__, ##__VA_ARGS__]  delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil]; dispatch_async(dispatch_get_main_queue(), ^{ [alert show]; }); }

GCD

Timer

dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 0.01 * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
    // Do something...
});

MVC

Singleton Object

+ (instancetype)sharedInstance {
   static id sharedInstance = nil;

   static dispatch_once_t onceToken;
   dispatch_once(&onceToken, ^{
      sharedInstance = [[self alloc] init];
   });

   return sharedInstance;
}

#Travis Ci

Encrypt Certificates

openssl aes-256-cbc -k "password" -in scripts/profile/name.mobileprovision -out scripts/profile/name.mobileprovision.enc -a
openssl aes-256-cbc -k "password" -in scripts/certs/developer.cer -out scripts/certs/developer.cer.enc -a
openssl aes-256-cbc -k "password" -in scripts/certs/developer.p12 -out scripts/certs/developer.cer.p12 -a

#Update Build Number

if [ "${CONFIGURATION}" = "Release" ]; then
buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$INFOPLIST_FILE")
buildNumber=$(($buildNumber + 1))
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "$INFOPLIST_FILE"
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}"
fi

OTA Install URL Prefix

itms-services://?action=download-manifest&url=<plist link>