Skip to content

Instantly share code, notes, and snippets.

View knight2010's full-sized avatar
๐Ÿ 
Working from home

Knight Captain knight2010

๐Ÿ 
Working from home
View GitHub Profile
@knight2010
knight2010 / README.swift
Last active November 23, 2023 07:50
Add new snippet
print("Awesome swift, https://dev.swift")
func locationManagerDidUpdate(notification: NSNotification) {
if let userInfo = notification.userInfo, locations = userInfo["locations"], newLocation = (locations as! NSArray).firstObject {
print("newLocation : \(newLocation)")
}
}
@knight2010
knight2010 / gist:53dc82e5cafe7d03e28f08efde505f88
Created June 1, 2017 10:00
Remove the cache while receiving memory warning
[[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationDidReceiveMemoryWarningNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * __unused notification) {
[_af_defaultImageCache removeAllObjects];
}];
//็ฌฌไธ€็งๆ–นๆณ•
NSDate *start = [NSDate date];
//2.ๆ นๆฎurlๅœฐๅ€ไธ‹่ฝฝๅ›พ็‰‡ๆ•ฐๆฎๅˆฐๆœฌๅœฐ๏ผˆไบŒ่ฟ›ๅˆถๆ•ฐๆฎ๏ผ‰
NSData *data = [NSData dataWithContentsOfURL:url];
NSDate *end = [NSDate date];
NSLog(@"็ฌฌไบŒๆญฅๆ“ไฝœ่Šฑ่ดน็š„ๆ—ถ้—ดไธบ%f",[end timeIntervalSinceDate:start]);
//็ฌฌไบŒ็งๆ–นๆณ•
CFTimeInterval start = CFAbsoluteTimeGetCurrent();
@knight2010
knight2010 / NSLayoutConstraint
Created March 30, 2017 07:28
NSLayoutConstraint
view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[noWorkoutsView]|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: views))
view.addConstraint(NSLayoutConstraint(item:noWorkoutsView,
attribute: .Top,
relatedBy: .Equal,
toItem: view,
attribute: .Top,
multiplier: 1.0,
constant: 0))