This file contains 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
// Doing something on the main thread | |
dispatch_queue_t myQueue = dispatch_queue_create("My Queue",NULL); | |
dispatch_async(myQueue, ^{ | |
// Perform long running process | |
dispatch_async(dispatch_get_main_queue(), ^{ | |
// Update the UI | |
}); |
This file contains 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
Taken From: http://stablekernel.com/blog/speeding-up-nscoding-with-macros/ | |
#define OBJC_STRINGIFY(x) @#x | |
#define encodeObject(x) [aCoder encodeObject:x forKey:OBJC_STRINGIFY(x)] | |
#define decodeObject(x) x = [aDecoder decodeObjectForKey:OBJC_STRINGIFY(x)] | |
#define encodeFloat(x) [aCoder encodeFloat:x forKey:OBJC_STRINGIFY(x)] | |
#define decodeFloat(x) x = [aDecoder decodeFloatForKey:OBJC_STRINGIFY(x)] | |
- (id)initWithCoder:(NSCoder *)aDecoder | |
{ |
This file contains 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
1) Choose the target you want to add to | |
2) Choose Build Settings | |
3) Search for 'macros' | |
4) Add a macro | |
To use the macro in the app: | |
#ifdef MACRO | |
// do some stuff | |
#elif OTHERMACRO | |
// do other stuff |
This file contains 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 *)appNameAndVersionNumberDisplayString { | |
NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary]; | |
NSString *appDisplayName = [infoDictionary objectForKey:@"CFBundleDisplayName"]; | |
NSString *majorVersion = [infoDictionary objectForKey:@"CFBundleShortVersionString"]; | |
NSString *minorVersion = [infoDictionary objectForKey:@"CFBundleVersion"]; | |
return [NSString stringWithFormat:@"%@, Version %@ (%@)", | |
appDisplayName, majorVersion, minorVersion]; | |
} |
This file contains 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
+(void)restart:(id)sender | |
{ | |
NSString *restartScript = @"while ps -p $1 > /dev/null; do sleep 0.1; done; open \"$2\""; | |
NSArray *arguments = [NSArray arrayWithObjects: | |
@"-c", restartScript, | |
@"", | |
[NSString stringWithFormat:@"%d",[[NSProcessInfo processInfo] processIdentifier]], | |
[[NSBundle mainBundle] bundlePath], | |
nil]; | |
[NSTask launchedTaskWithLaunchPath:@"/bin/sh" arguments:arguments]; |
This file contains 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
+ (<#Class#> *)sharedManager | |
{ | |
static <#Class#> *sharedManager = nil; | |
static dispatch_once_t onceToken; | |
dispatch_once(&onceToken, ^{ | |
sharedManager = [[<#Class#> alloc] init]; | |
// other initialisation stuff | |
}); | |
return sharedManager; | |
} |
This file contains 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
#pragma mark - | |
#pragma mark UIImagePickerController Delegate Methods | |
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info | |
{ | |
// dismiss the picker | |
if (self.popover) | |
{ | |
[self.popover dismissPopoverAnimated:YES]; | |
self.popover = nil; |
This file contains 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
UIImagePickerController *libraryController = [[UIImagePickerController alloc] init]; | |
libraryController.delegate = self; | |
libraryController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; | |
libraryController.allowsEditing = YES; | |
// if on the ipad, show the library in a popover | |
if (iPad) | |
{ | |
UIPopoverController *libraryPopover = [[UIPopoverController alloc] initWithContentViewController:libraryController]; | |
[libraryPopover presentPopoverFromRect:self.rectToPresentPopoverFrom inView:self.scrollView permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; |
This file contains 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
// setup a picker for the camera | |
UIImagePickerController *cameraController = [[UIImagePickerController alloc] init]; | |
cameraController.delegate = self; | |
cameraController.sourceType = UIImagePickerControllerSourceTypeCamera; | |
cameraController.allowsEditing = YES; | |
[self presentViewController:cameraController animated:YES completion:nil]; |
This file contains 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
// Link Against Assets Library | |
// #import <AssetsLibrary/AssetsLibrary.h> | |
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init]; | |
// Enumerate just the photos and videos group by using ALAssetsGroupSavedPhotos. | |
[library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) | |
{ | |
// Within the group enumeration block, filter to enumerate just photos. | |
[group setAssetsFilter:[ALAssetsFilter allPhotos]]; |
NewerOlder