This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dispatch_queue_t serialQueue = dispatch_queue_create(""imagesQueue"", DISPATCH_QUEUE_SERIAL); | |
dispatch_async(serialQueue, ^{ | |
// Perform long running process | |
dispatch_async(dispatch_get_main_queue(), ^{ | |
// Update the UI | |
}); | |
});" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); | |
dispatch_async(queue, ^{ | |
// Perform long running process | |
dispatch_async(dispatch_get_main_queue(), ^{ | |
// Update the UI | |
}); | |
});" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (instancetype)init { | |
self = [super init]; | |
if (self) { | |
// perform initialization | |
} | |
return self; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSDate to NSString: | |
NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init]; | |
[dateFormatter setDateFormat:@"yyyy-MM-dd"]; | |
NSDate* myDate = [NSDate date]; | |
NSString *stringFromDate = [dateFormatter stringFromDate:myDate]; | |
NSString to NSDate: | |
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "GCDWebServer.h" | |
#import "GCDWebServerDataResponse.h" | |
.......... | |
@interface AppDelegate (){ | |
GCDWebServer* _webServer; | |
} | |
- (void)startWebServer{ | |
NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); | |
NSString *documentsDirectory = [paths objectAtIndex:0]; | |
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.log",stringFromDate]]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSLog(@"%s",__PRETTY_FUNCTION__); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (NSString*)readString{ | |
NSURL *filePath = [[NSBundle mainBundle] URLForResource:@"info" withExtension:@"txt"]; | |
NSString *path = [filePath path]; | |
NSString *content = @""; | |
if([[NSFileManager defaultManager] fileExistsAtPath:path]) { | |
// Do something here | |
content = [NSString stringWithContentsOfFile:path | |
encoding:NSUTF8StringEncoding | |
error:NULL]; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(NSString*)generateHMACwith :(NSString* )key :(NSString*)data{ | |
const char *cKey = [key cStringUsingEncoding:NSUTF8StringEncoding]; | |
const char *cData = [data cStringUsingEncoding:NSUTF8StringEncoding]; | |
unsigned char cHMAC[CC_SHA256_DIGEST_LENGTH]; | |
CCHmac(kCCHmacAlgSHA256, | |
cKey, | |
strlen(cKey), | |
cData, | |
strlen(cData), | |
cHMAC); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (NSData *)generateHMACwith:(NSData *)key key:(NSData *)data { | |
NSMutableData *macOut = [NSMutableData dataWithLength:CC_SHA256_DIGEST_LENGTH]; | |
CCHmac( kCCHmacAlgSHA256, | |
key.bytes, | |
key.length, | |
data.bytes, | |
data.length, | |
macOut.mutableBytes); | |
return macOut; | |
} |