Skip to content

Instantly share code, notes, and snippets.

func zip<X, Y, Z>(first: X[], second: Y[], transform: (X, Y) -> (Z)) -> Array<Z> {
var zipped = Z[]()
for i in 0..min(first.count, second.count) {
zipped.append(transform(first[i], second[i]))
}
return zipped
}
@vascoorey
vascoorey / gist:10992462
Last active August 29, 2015 13:59
Delete CoreData store file in the event of a model mismatch
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
...
// Get the path for our model (in this case it's named 'cache')
NSURL *url = [[NSBundle mainBundle] URLForResource:@"cache" withExtension:@"momd"];
NSPersistentStoreCoordinator *psc = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[[NSManagedObjectModel alloc] initWithContentsOfURL:url]]; /* get a coordinator */
NSString *sourceStoreType = nil;/* type for the source store, or nil if not known */ ;
NSString *path = [NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES) firstObject];
// Figure out the full path where our store is located
path = [path stringByAppendingFormat:@"/%@/Cache", [[[[NSBundle mainBundle] bundleIdentifier] componentsSeparatedByString:@"."] lastObject]];
NSURL *sourceStoreURL = [NSURL fileURLWithPath:path]; /* URL for the source store */ ;