Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Nimble.podspec
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Pod::Spec.new do |s|
s.name = "Nimble"
s.version = "0.0.1"
s.version = "0.0.2"
s.summary = "Core Data and iCloud made nimble and fast."
s.homepage = "http://github.com/marcosero/Nimble"
s.license = 'MIT'
s.author = { "Marco Sero" => "marco@marcosero.com" }
s.source = { :git => "http://github.com/marcosero/Nimble", :tag => "0.0.1" }
s.source = { :git => "https://github.com/xhzengAIB/Nimble.git"}
s.platform = :ios, '6.0'
s.source_files = 'Nimble'
s.source_files = 'Nimble/*.{h,m}','Nimble/**/*.{h,m}'
s.framework = 'CoreData'
s.requires_arc = true
end
5 changes: 5 additions & 0 deletions Nimble/Categories/NimbleStore+Savers.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@

+ (void)nb_saveInMain:(NimbleSimpleBlock)changes;

+ (void)nb_saveInMain:(NimbleSimpleBlock)changes withMergePolicy:(NSMergePolicy *)mergePolicy;

+ (void)nb_saveInMainWaiting:(NimbleSimpleBlock)changes;

+ (void)nb_saveInMainWaiting:(NimbleSimpleBlock)changes withMergePolicy:(NSMergePolicy *)mergePolicy;

/**
* Perform all the changes in a background queue and then merge everything into the main context
Expand All @@ -45,4 +48,6 @@
*/
+ (void)nb_saveInBackground:(NimbleSimpleBlock)changes completion:(NimbleErrorBlock)completion;

+ (void)nb_saveInBackground:(NimbleSimpleBlock)changes withMergePolicy:(NSMergePolicy *)mergePolicy completion:(NimbleErrorBlock)completion;

@end
129 changes: 77 additions & 52 deletions Nimble/Categories/NimbleStore+Savers.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,43 +29,62 @@ @implementation NimbleStore (Savers)

+ (void)nb_saveInMain:(NimbleSimpleBlock)changes
{
NSParameterAssert(changes);

NSManagedObjectContext *context = [NSManagedObjectContext nb_mainContext];

[context performBlock:^{

changes(NBMainContext);

NSError *error;
[context save:&error];

if (error) {
NBLog(@"Error saving main context: %@", error);
}
[self nb_saveInMain:changes withMergePolicy:NSErrorMergePolicy];
}

}];
+ (void)nb_saveInMain:(NimbleSimpleBlock)changes withMergePolicy:(NSMergePolicy *)mergePolicy
{
NSParameterAssert(changes);

NSManagedObjectContext *context = [NSManagedObjectContext nb_mainContext];

[context performBlock:^{
NSMergePolicy *originalMergePolicy = context.mergePolicy;
context.mergePolicy = mergePolicy;

changes(NBMainContext);

NSError *error;
[context save:&error];

context.mergePolicy = originalMergePolicy;
if (error) {
NBLog(@"Error saving main context: %@", error);
}

}];
}

+ (void)nb_saveInMainWaiting:(NimbleSimpleBlock)changes
{
NSParameterAssert(changes);

NSManagedObjectContext *context = [NSManagedObjectContext nb_mainContext];

[context performBlockAndWait:^{

changes(NBMainContext);
[self nb_saveInMainWaiting:changes withMergePolicy:NSErrorMergePolicy];
}

NSError *error;
[context save:&error];
+ (void)nb_saveInMainWaiting:(NimbleSimpleBlock)changes withMergePolicy:(NSMergePolicy *)mergePolicy
{
NSParameterAssert(changes);

NSManagedObjectContext *context = [NSManagedObjectContext nb_mainContext];

[context performBlockAndWait:^{

NSMergePolicy *originalMergePolicy = context.mergePolicy;
context.mergePolicy = mergePolicy;

changes(NBMainContext);

NSError *error;
[context save:&error];

context.mergePolicy = originalMergePolicy;
if (error) {
NBLog(@"Error saving main context: %@", error);
}

}];
}

if (error) {
NBLog(@"Error saving main context: %@", error);
}

}];
}

+ (void)nb_saveInBackground:(NimbleSimpleBlock)changes
{
Expand All @@ -74,30 +93,36 @@ + (void)nb_saveInBackground:(NimbleSimpleBlock)changes

+ (void)nb_saveInBackground:(NimbleSimpleBlock)changes completion:(NimbleErrorBlock)completion
{
NSParameterAssert(changes);

NSManagedObjectContext *backgroundContext = [NSManagedObjectContext nb_backgroundContext];

[backgroundContext performBlock:^{

changes(NBBackgroundContext);

NSError *error;
[backgroundContext save:&error];

if (error) {
NBLog(@"Error saving background context: %@", error);
}

if (completion) {
dispatch_async(dispatch_get_main_queue(), ^{
completion(nil);
});
}

}];

[self nb_saveInBackground:changes withMergePolicy:NSErrorMergePolicy completion:completion];
}

+ (void)nb_saveInBackground:(NimbleSimpleBlock)changes withMergePolicy:(NSMergePolicy *)mergePolicy completion:(NimbleErrorBlock)completion {
NSParameterAssert(changes);

NSManagedObjectContext *backgroundContext = [NSManagedObjectContext nb_backgroundContext];

[backgroundContext performBlock:^{

NSMergePolicy *originalMergePolicy = backgroundContext.mergePolicy;
backgroundContext.mergePolicy = mergePolicy;

changes(NBBackgroundContext);

NSError *error;
[backgroundContext save:&error];

backgroundContext.mergePolicy = originalMergePolicy;
if (error) {
NBLog(@"Error saving background context: %@", error);
}

if (completion) {
dispatch_async(dispatch_get_main_queue(), ^{
completion(nil);
});
}

}];
}

@end
11 changes: 11 additions & 0 deletions Nimble/Main Store/NimbleStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@


#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>

#define NBLog(...) NSLog(@"Nimble >> %s\n\t%@", __PRETTY_FUNCTION__, [NSString stringWithFormat:__VA_ARGS__])

Expand Down Expand Up @@ -67,6 +68,16 @@ typedef void (^NimbleErrorBlock)(NSError *error);
*/
+ (BOOL)nb_setupStore:(NSError **)error;


/**
* Setup a autoMigrating store with the default filename
*
* @param error
*
* @return setup status
*/
+ (BOOL)nb_setupAutoMigratingSqliteStore:(NSError **)error;

/**
Setup a store with a custom filename
*/
Expand Down
8 changes: 8 additions & 0 deletions Nimble/Main Store/NimbleStore.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ + (BOOL)nb_setupStore:(NSError **)error
return [self nb_setupStoreWithFilename:[self.class nb_defaultStoreName] error:error];
}

+ (BOOL)nb_setupAutoMigratingSqliteStore:(NSError **)error
{
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
[NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];
return [self nb_setupStoreWithName:[self.class nb_defaultStoreName] storeType:NSSQLiteStoreType options:options error:error];
}

+ (BOOL)nb_setupStoreWithFilename:(NSString *)filename error:(NSError **)error
{
NSParameterAssert(filename);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,37 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDESourceControlProjectFavoriteDictionaryKey</key>
<false/>
<key>IDESourceControlProjectIdentifier</key>
<string>DB398F12-C64F-4246-A5E1-C0092C32F193</string>
<string>83E05706-1C71-40B6-9C58-5C9CBE62AEEE</string>
<key>IDESourceControlProjectName</key>
<string>NimbleDemo</string>
<key>IDESourceControlProjectOriginsDictionary</key>
<dict>
<key>29CB7ABD-0461-41C6-803C-14162FDA686B</key>
<string>ssh://bitbucket.org/marcosero/nimble.git</string>
<key>D774E5F0-7D41-4628-AEC0-CE3CDEB9096A</key>
<string>https://github.com/xhzengAIB/Nimble.git</string>
</dict>
<key>IDESourceControlProjectPath</key>
<string>NimbleDemo.xcodeproj/project.xcworkspace</string>
<key>IDESourceControlProjectRelativeInstallPathDictionary</key>
<dict>
<key>29CB7ABD-0461-41C6-803C-14162FDA686B</key>
<key>D774E5F0-7D41-4628-AEC0-CE3CDEB9096A</key>
<string>../..</string>
</dict>
<key>IDESourceControlProjectURL</key>
<string>ssh://bitbucket.org/marcosero/nimble.git</string>
<string>https://github.com/xhzengAIB/Nimble.git</string>
<key>IDESourceControlProjectVersion</key>
<integer>110</integer>
<key>IDESourceControlProjectWCCIdentifier</key>
<string>29CB7ABD-0461-41C6-803C-14162FDA686B</string>
<string>D774E5F0-7D41-4628-AEC0-CE3CDEB9096A</string>
<key>IDESourceControlProjectWCConfigurations</key>
<array>
<dict>
<key>IDESourceControlRepositoryExtensionIdentifierKey</key>
<string>public.vcs.git</string>
<key>IDESourceControlWCCIdentifierKey</key>
<string>29CB7ABD-0461-41C6-803C-14162FDA686B</string>
<string>D774E5F0-7D41-4628-AEC0-CE3CDEB9096A</string>
<key>IDESourceControlWCCName</key>
<string>Nimble</string>
</dict>
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0510"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "A9040B5A178E0ECC00CCE8EF"
BuildableName = "NimbleDemo.app"
BlueprintName = "NimbleDemo"
ReferencedContainer = "container:NimbleDemo.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
buildConfiguration = "Debug">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "A9541F181793572A008D92FC"
BuildableName = "NimbleDemo Tests.xctest"
BlueprintName = "NimbleDemo Tests"
ReferencedContainer = "container:NimbleDemo.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "A9040B5A178E0ECC00CCE8EF"
BuildableName = "NimbleDemo.app"
BlueprintName = "NimbleDemo"
ReferencedContainer = "container:NimbleDemo.xcodeproj">
</BuildableReference>
</MacroExpansion>
</TestAction>
<LaunchAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
allowLocationSimulation = "YES">
<BuildableProductRunnable>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "A9040B5A178E0ECC00CCE8EF"
BuildableName = "NimbleDemo.app"
BlueprintName = "NimbleDemo"
ReferencedContainer = "container:NimbleDemo.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
buildConfiguration = "Release"
debugDocumentVersioning = "YES">
<BuildableProductRunnable>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "A9040B5A178E0ECC00CCE8EF"
BuildableName = "NimbleDemo.app"
BlueprintName = "NimbleDemo"
ReferencedContainer = "container:NimbleDemo.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>NimbleDemo.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
<key>A9040B5A178E0ECC00CCE8EF</key>
<dict>
<key>primary</key>
<true/>
</dict>
<key>A9541F181793572A008D92FC</key>
<dict>
<key>primary</key>
<true/>
</dict>
</dict>
</dict>
</plist>