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
// this code will cause a UIView to shake--good for "login error" | |
CAKeyframeAnimation * anim = [ CAKeyframeAnimation animationWithKeyPath:@"transform" ] ; | |
anim.values = [ NSArray arrayWithObjects: | |
[ NSValue valueWithCATransform3D:CATransform3DMakeTranslation(-5.0f, 0.0f, 0.0f) ], | |
[ NSValue valueWithCATransform3D:CATransform3DMakeTranslation(5.0f, 0.0f, 0.0f) ], | |
nil ] ; | |
anim.autoreverses = YES ; | |
anim.repeatCount = 2.0f ; | |
anim.duration = 0.07f ; |
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
// 01. init method forbidden | |
- (id)init { | |
@throw [NSException exceptionWithName:NSInternalInconsistencyException | |
reason:@"-init is not a valid initializer for the class Foo" | |
userInfo:nil]; | |
return 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
- (NSArray *)matchUrlInString:(NSString *)string | |
{ | |
NSError *error = NULL; | |
NSDataDetector *detectorLink = [NSDataDetector dataDetectorWithTypes:NSTextCheckingTypeLink error:&error]; | |
NSArray *urlMatchArr = [detectorLink matchesInString:string options:NSMatchingReportCompletion range:NSMakeRange(0, string.length)]; | |
return urlMatchArr; | |
} |
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
######################### | |
# .gitignore file for Xcode4 and Xcode5 Source projects | |
# | |
# Apple bugs, waiting for Apple to fix/respond: | |
# | |
# 15564624 - what does the xccheckout file in Xcode5 do? Where's the documentation? | |
# | |
# Version 2.3 | |
# For latest version, see: http://stackoverflow.com/questions/49478/git-ignore-file-for-xcode-projects | |
# |
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)logClassMethods:(Class)class | |
{ | |
NSString* className = NSStringFromClass(class); | |
const char* cClassName = [className UTF8String]; | |
id theClass = objc_getClass(cClassName); | |
unsigned int outCount; | |
Method* m = class_copyMethodList(theClass, &outCount); | |
NSLog(@"Class: %@, has methods: %d", className, outCount); | |
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
// Call this method somewhere in your view controller setup code. | |
- (void)registerForKeyboardNotifications | |
{ | |
[[NSNotificationCenter defaultCenter] addObserver:self | |
selector:@selector(keyboardWasShown:) | |
name:UIKeyboardDidShowNotification object:nil]; | |
[[NSNotificationCenter defaultCenter] addObserver:self | |
selector:@selector(keyboardWillBeHidden:) | |
name:UIKeyboardWillHideNotification object: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
NSString *str = @"中国"; | |
CFStringRef aCFString = (__bridge CFStringRef)str; | |
CFMutableStringRef string = CFStringCreateMutableCopy(NULL, 0, aCFString); | |
CFStringTransform(string, NULL, kCFStringTransformMandarinLatin, NO); | |
CFStringTransform(string, NULL, kCFStringTransformStripDiacritics, NO); | |
NSLog(@"中国 = %@", string); |
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 - CoreDataAbout | |
- (void)saveContext | |
{ | |
NSError* error = nil; | |
NSManagedObjectContext *managedObjectContext = self.managedObjectContext; | |
if (managedObjectContext != nil) { | |
if ([managedObjectContext hasChanges] && ![managedObjectContext save:&error]) { | |
NSLog(@"Unresolved error :%@, %@", error, [error userInfo]); | |
abort(); |
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
NSLog(@"HostName: %@", [[NSProcessInfo processInfo] hostName]); | |
//globallyUniqueString 唯一的标示符,每次调用都会不一样,可以用作一些临时缓存文件的名字 | |
NSLog(@"GlobalUniqueString: %@", [[NSProcessInfo processInfo] globallyUniqueString]); | |
//操作系统名称 | |
NSLog(@"OperatingSystemName: %@", [[NSProcessInfo processInfo] operatingSystemName]); | |
//操作系统版本 | |
NSLog(@"OperatingSystemVersion: %@", [[NSProcessInfo processInfo] operatingSystemVersionString]); | |
//物理内存 | |
NSLog(@"PhysicalMem: %llu", [[NSProcessInfo processInfo] physicalMemory]); | |
//进程名称 |
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
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |