View gist:4273999
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
NSArray *reversedArray = array.reverseObjectEnumerator.allObjects; |
View gist:4274042
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
#import "objc/runtime.h" | |
Class NSClassFromString(NSString *aClassName) { | |
NSLog(@"%@", aClassName); | |
id class = objc_getClass(aClassName.UTF8String); | |
return class; | |
} |
View gist:4325186
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
tell application "Final Cut Pro" to activate | |
tell application "System Events" | |
if UI elements enabled is false then | |
keystroke "]" using shift down | |
else | |
tell process "Final Cut Pro" | |
--click menu item "In to Out" of menu 1 of menu item "Play" of menu "Mark" of menu bar 1 | |
click menu item 1 of menu 1 of menu item 21 of menu 6 of menu bar 1 | |
end tell | |
end if |
View NSUserDefaults+RegisterDefault.m
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
@implementation NSUserDefaults (RegisterDefault) | |
- (void)registerDefaultObject:(id)value forKey:(NSString *)defaultName { | |
NSMutableDictionary *mDict = [self volatileDomainForName:NSRegistrationDomain].mutableCopy; | |
[mDict setObject:value forKey:defaultName]; | |
[self setVolatileDomain:mDict forName:NSRegistrationDomain]; | |
} | |
@end |
View gist:6785077
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
// select language from application's localizations | |
NSBundle *mainBundle = [NSBundle mainBundle]; | |
NSArray *localizations = mainBundle.localizations; | |
NSString *localization = localizations.lastObject; | |
// search bundle contains Localizable.string | |
NSURL *URL = [mainBundle URLForResource:@"Localizable" withExtension:@"strings" subdirectory:nil localization:localization]; | |
NSBundle *bundle = [NSBundle bundleWithURL:URL.URLByDeletingLastPathComponent]; | |
// get localized string from bundle |
View gist:10550725
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
// UIFontDescriptor on iOS 7 or later | |
NSDictionary *traitsAttributes = @{UIFontSymbolicTrait: @(UIFontDescriptorTraitMonoSpace)}; | |
NSDictionary *fontAttributes = @{UIFontDescriptorTraitsAttribute: traitsAttributes}; | |
UIFontDescriptor *fontDescriptor = [UIFontDescriptor fontDescriptorWithFontAttributes:fontAttributes]; | |
NSArray *array = [fontDescriptor matchingFontDescriptorsWithMandatoryKeys:nil]; | |
for (UIFontDescriptor *descriptor in array) { | |
NSLog(@"%@", descriptor.postscriptName); | |
// NSLog(@"%@", [descriptor objectForKey:UIFontDescriptorNameAttribute]); | |
// NSLog(@"%@", [descriptor objectForKey:UIFontDescriptorVisibleNameAttribute]); |
View gist:b50d187fed615772b974
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
ObjC.import('Cocoa') | |
//var array = $.NSArray.arrayWithObjects($('jp'), $('us'), $('es'), $('ru')); | |
var array = $(['jp', 'us', 'es', 'ru']); | |
for (var i=0; i<array.count; i++) { | |
var string = array.objectAtIndex(i); | |
var URLString = $.NSString.stringWithFormat('http://store.apple.com/%@/product/MB110CH/B/', string); | |
var URL = $.NSURL.URLWithString(URLString) | |
$.NSWorkspace.sharedWorkspace.openURL(URL) | |
} |
View Assert.m
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
// NSAssert can be used in method | |
- (void)method | |
{ | |
NSAssert(false, @"message"); | |
} | |
// NSCAssert can be used in function | |
void func() | |
{ | |
NSCAssert(false, @"message"); |
View DecimalNumberString.m
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
+ (BOOL)containsOnlyDecimalNumbers1:(NSString *)string | |
{ | |
NSCharacterSet *characterSet = [NSCharacterSet characterSetWithCharactersInString:string]; | |
return [[NSCharacterSet decimalDigitCharacterSet] isSupersetOfSet:characterSet]; | |
} | |
+ (BOOL)containsOnlyDecimalNumbers2:(NSString *)string | |
{ | |
NSCharacterSet *characterSet = [NSCharacterSet decimalDigitCharacterSet].invertedSet; | |
return [string rangeOfCharacterFromSet:characterSet].length == 0; |
View PrintMethodPropertyIvar.m
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
#import <objc/runtime.h> | |
void PrintMethodList(Class cls) { | |
printf("// Method List of %s\n", class_getName(cls)); | |
unsigned int outCount; | |
Method *methodList = class_copyMethodList(cls, &outCount); | |
for (unsigned int i=0; i<outCount; i++) { | |
Method m = methodList[i]; | |
SEL sel = method_getName(m); | |
printf("%s\n", sel_getName(sel)); |
OlderNewer