Skip to content

Instantly share code, notes, and snippets.

View nishabe's full-sized avatar

nish abe nishabe

View GitHub Profile
@nishabe
nishabe / OBJC: Get a file from documents directory
Last active August 12, 2018 18:23
OBJC: Get path of a file which is in documents directory
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.log",stringFromDate]];
@nishabe
nishabe / OBJC: GCD Web Server Set up to access a log file
Last active August 12, 2018 18:22
OBJC: GCD Web Server Set up to access a log file
#import "GCDWebServer.h"
#import "GCDWebServerDataResponse.h"
..........
@interface AppDelegate (){
GCDWebServer* _webServer;
}
- (void)startWebServer{
NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
@nishabe
nishabe / OBJC: Date Formatter
Last active August 12, 2018 18:22
OBJC: Date Formatter Sample
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];
@nishabe
nishabe / OBJC: A Typical Init.txt
Last active August 12, 2018 18:22
OBJC: A Typical init
- (instancetype)init {
self = [super init];
if (self) {
// perform initialization
}
return self;
}
@nishabe
nishabe / OBJC: GCD: Creating a concurrent queue
Last active August 12, 2018 18:22
OBJC: GCD: Creating a concurrent queue
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
});
});"
@nishabe
nishabe / OBJC: GCD: Creating a serial queue
Last active August 12, 2018 18:21
OBJC: GCD: Creating a serial queue
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
});
});"
@nishabe
nishabe / OBJC: Suppress a specific compiler warning.txt
Last active August 12, 2018 18:21
OBJC: Suppress a specific compiler warning
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
// Your code here
#pragma clang diagnostic pop
@nishabe
nishabe / OBJC: Force Only Once Code Execution.txt
Last active August 12, 2018 18:21
OBJC: Force code execution only once
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
// Your code here
});
@nishabe
nishabe / OBJC:Get reference of Appdelegate.txt
Last active August 12, 2018 18:21
OBJC:Get reference of Appdelegate.txt
var appDelegate = UIApplication.sharedApplication().delegate as AppDelegate
@nishabe
nishabe / OBJC:Get applicationDocumentsDirectory
Last active August 12, 2018 18:20
OBJC:Get applicationDocumentsDirectory
- (NSURL *)applicationDocumentsDirectory {
return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
}