This file contains hidden or 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
func checkShouldDownloadFileAtLocation(urlString:String, completion:((shouldDownload:Bool) -> ())?) { | |
var request = NSMutableURLRequest(URL: NSURL(string: urlString)!) | |
request.HTTPMethod = "HEAD" | |
var session = NSURLSession.sharedSession() | |
var err: NSError? | |
var task = session.dataTaskWithRequest(request, completionHandler: { [weak self] data, response, error -> Void in | |
if let strongSelf = self { | |
var isModified = false |
This file contains hidden or 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
extension NSManagedObject { | |
func safeSetValuesForKeys(dictionary:[NSObject:AnyObject]) { | |
let attributes: [NSObject:AnyObject] = self.entity.attributesByName | |
var finalValue : AnyObject? = nil | |
for (attribute, value) in attributes { | |
if let val : NSNull = value as? NSNull { | |
continue; | |
} |
This file contains hidden or 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)writeAnimatedGIFToPath:(NSURL*)path withImages:(NSArray*)images duration:(CGFloat)duration completionBlock:(dispatch_block_t)completionBlock; | |
{ | |
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ | |
NSDictionary *fileProperties = @{ | |
(__bridge id)kCGImagePropertyGIFDictionary: @{ | |
(__bridge id)kCGImagePropertyGIFLoopCount: @0, // 0 means loop forever | |
} | |
}; | |
NSDictionary *frameProperties = @{ |
This file contains hidden or 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
# Here's what it looks like over multiple lines. Use the single line | |
# one below in the console or it won't work. | |
# ["AL","AK","AZ","AR","CA","CO","CT","DE","FL","GA","HI","ID","IL", | |
# "IN","IA","KS","KY","LA","ME","MD","MA","MI","MN","MS","MO","MT", | |
# "NE","NV","NH","NJ","NM","NY","NC","ND","OH","OK","OR","PA","RI", | |
# "SC","SD","TN","TX","UT","VT","VA","WA","WV","WI","WY","AS","DC", | |
# "FM","GU","MH","MP","PW","PR","VI", | |
# "AE","AA","AE","AE","AE","AP"].each { |st| group = Group.new( :name => st); group.save } | |
["AL","AK","AZ","AR","CA","CO","CT","DE","FL","GA","HI","ID","IL","IN","IA","KS","KY","LA","ME","MD","MA","MI","MN","MS","MO","MT","NE","NV","NH","NJ","NM","NY","NC","ND","OH","OK","OR","PA","RI","SC","SD","TN","TX","UT","VT","VA","WA","WV","WI","WY","AS","DC","FM","GU","MH","MP","PW","PR","VI","AE","AA","AE","AE","AE","AP"].each { |st| group = Group.new( :name => st); group.save } |
This file contains hidden or 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
NSError *error = nil; | |
NSData *json = [NSData dataWithContentsOfFile:path]; | |
id object = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableContainers error:&error]; | |
// object is a dictionary or an array you can now use |
NewerOlder