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
| // Copyright (c) 2017 Kristopher Johnson | |
| // | |
| // Permission is hereby granted, free of charge, to any person obtaining a | |
| // copy of this software and associated documentation files (the | |
| // "Software"), to deal in the Software without restriction, including | |
| // without limitation the rights to use, copy, modify, merge, publish, | |
| // distribute, sublicense, and/or sell copies of the Software, and to | |
| // permit persons to whom the Software is furnished to do so, subject to | |
| // the following conditions: | |
| // |
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
| [[managedObject managedObjectContext] performBlock:^{ | |
| NSString *value = [managedObject someValue]; | |
| [NSOperationQueue mainQueue] addOperationWithBlock:^{ | |
| [[self label] setText:value]; | |
| }]; | |
| }]; |
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) saveManagedObjectContext:(NSManagedObjectContext *)managedObjectContext withCompletion::(void (^)(BOOL, NSError *))completio{ | |
| managedObjectContext performBlock:^{ | |
| NSError *error = nil; | |
| if (![managedObjectContext save:&error]){ | |
| completion(NO, error); | |
| } else { | |
| if ([managedObjectContext parentContext] != nil){ | |
| [self saveManagedObjectContext:[managedObjectContext parentContext] withCompletion:completion]; | |
| } else { |
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
| [managedObjectContext performBlock:^{ | |
| NSError *error = nil; | |
| if (![managedObjectContext save:&error]){ | |
| [self handleError:error]; | |
| } | |
| }]; |
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) allPeopleInManagedObjectContext:(NSManagedObjectContext *)managedObjectContext withCompletion:(void (^)(NSArray*, NSError*))completion { | |
| [managedObjectContext performBlock:^{ | |
| NSError *error = nil; | |
| NSArray *results = nil; | |
| NSFetchRequest *fetchRequest = nil; | |
| NSPredicate *predicate = nil; | |
| NSEntityDescription *entity = nil; | |
| fetchRequest = [[NSFetchRequest alloc] init]; | |
| entity = [NSEntityDescription entityForName:@"Person" inManagedObjectContext:context]; |
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
| #!/usr/bin/env ruby | |
| device_types_output = `xcrun simctl list devicetypes` | |
| device_types = device_types_output.scan /(.*) \((.*)\)/ | |
| runtimes_output = `xcrun simctl list runtimes` | |
| runtimes = runtimes_output.scan /(.*) \(.*\) \((com.apple[^)]+)\)$/ | |
| devices_output = `xcrun simctl list devices` | |
| devices = devices_output.scan /\s\s\s\s(.*) \(([^)]+)\) (.*)/ |
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
| NSEntityDescription *entityDescription = nil; | |
| NSArray *attributeNames = nil; | |
| NSDictionary *mappedValues = nil; | |
| entityDescription = [managedObject entity]; | |
| attributeNames = [[entity attributesByName] allKeys]; | |
| mappedValues = [jsonObject dictionaryWithValuesForKeys:attributeKeys]; | |
| [managedObject setValuesForKeysWithDictionary:mappedValues]; |
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
| group = dispatch_group_create(); | |
| dispatch_group_enter(group); | |
| [context performBlock:^{ | |
| result = [context executeFetch:... | |
| dispatch_group_leave(group); | |
| }]; | |
| groupResult = dispatch_group_wait(group, DISPATCH_TIME_FOREVER); |
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) fetchThingsWithCompletion:(void (^)(NSArray *, NSError *))completion{ | |
| [context performBlock:^{ | |
| result = [context executeFetch:... | |
| if (completion != nil){ | |
| completion(result, error); | |
| } | |
| }]; | |
| } |
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
| /* | |
| Some syntactic sugar for dealing with Time in Swift | |
| Examples: | |
| 3.days.inHours | |
| 3.6.hours.ago | |
| 12.hours.inDays | |
| */ | |