Skip to content

Instantly share code, notes, and snippets.

@pkh
pkh / gist:363c27afc310fe1563f8
Created April 24, 2015 15:50
Quicksort Algorithm in Objective-C
- (void)sortMyArray
{
NSMutableArray *unsorted = [NSMutableArray arrayWithArray:@[@67, @1, @14, @22, @77, @23, @21, @17, @99, @107, @89, @20]];
NSLog(@"Unsorted:");
NSLog(@"%@",unsorted);
NSMutableArray *sorted = [self quickSort:unsorted];
NSLog(@"Sorted:");
NSLog(@"%@",sorted);
}
@pkh
pkh / gist:c2e44eb6a11d62b83977
Last active October 5, 2020 13:18
Helpful method to dismiss ALL view controllers presented on top of a root view/navigation controller.
/**
Helpful method to dismiss ALL view controllers presented on top of a
root view/navigation controller.
This method is useful if you have a variable number of view controllers
that you'd need to dimiss to return to a base view. Used for my purposes
from the AppDelegate class during the process of handling the opening of
a URL scheme.
This method also relies on implementing a category on UIViewController
@pkh
pkh / ios-archive-build.sh
Created January 15, 2015 22:53
Two commands to archive and build an iOS ipa file from the command line. Used to be able to build an ipa file without a provisioning profile (for later re-wrapping).
# Create an .xcarchive and an .ipa file from the command line (in order to build the ipa without a provisioning profile).
# It was build with 2 successive commands, one to create the .xcarchive file, and the second to build the actual ipa file.
# Your "SchemeName" here is typically the name of your app.
# To create the .xcarchive file:
xcodebuild -scheme SchemeName clean archive -archivePath build/SchemeName
# To create the .ipa file:
xcodebuild -exportArchive -exportFormat ipa -archivePath "build/SchemeName.xcarchive" -exportPath "build/SchemeName.ipa"
@pkh
pkh / gist:4454105
Created January 4, 2013 16:57
List all fonts available to an iOS app
NSArray *familyNames = [UIFont familyNames];
for ( NSString *familyName in familyNames ) {
printf( "Family: %s \n", [familyName UTF8String] );
NSArray *fontNames = [UIFont fontNamesForFamilyName:familyName];
for ( NSString *fontName in fontNames ) {
printf( "\tFont: %s \n", [fontName UTF8String] );
}
}
@pkh
pkh / gist:3427169
Created August 22, 2012 16:20
An Objective-C function for parsing a comma-delimited line of text while preserving commas located within fields. End of the line is detected with either a '\n' newline character or the end of the character stream.
- (NSMutableArray *)parseCSVStringIntoArray:(NSString *)csvString {
NSMutableArray *csvDataArray = [[NSMutableArray alloc] init];
// break string into an array of individual characters
NSMutableArray *characters = [[NSMutableArray alloc] initWithCapacity:[csvString length]];
int csvStringLength = [csvString length];
for (int c=0; c < csvStringLength; c++) {
NSString *ichar = [NSString stringWithFormat:@"%c", [csvString characterAtIndex:c]];
[characters addObject:ichar];