Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: xebia/ios-DemoForBlog
base: aee57aaa9f
...
head fork: xebia/ios-DemoForBlog
compare: 21b5e9835b
  • 3 commits
  • 9 files changed
  • 0 commit comments
  • 1 contributor
View
12 DemoForBlog.xcodeproj/project.pbxproj
@@ -29,6 +29,7 @@
9030DF2D14E2BA9F00325CFD /* XSDEntityNames.m in Sources */ = {isa = PBXBuildFile; fileRef = 9030DF2C14E2BA9F00325CFD /* XSDEntityNames.m */; };
9030DF3014E2BB2E00325CFD /* CoreData.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9030DF2F14E2BB2E00325CFD /* CoreData.framework */; };
9030DF3714E2BD3C00325CFD /* DemoForBlogModel.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 9030DF3514E2BD3C00325CFD /* DemoForBlogModel.xcdatamodeld */; };
+ 9034894B14E3D74600ED8748 /* XSDDemo.m in Sources */ = {isa = PBXBuildFile; fileRef = 9034894A14E3D74600ED8748 /* XSDDemo.m */; };
90A5D8E714E3C5D700D1DB07 /* XSDSyncOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = 90A5D8E614E3C5D700D1DB07 /* XSDSyncOperation.m */; };
/* End PBXBuildFile section */
@@ -69,12 +70,14 @@
9030DF0E14E2AF4A00325CFD /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
9030DF1014E2AF4A00325CFD /* DemoForBlogTests.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DemoForBlogTests.h; sourceTree = "<group>"; };
9030DF1114E2AF4A00325CFD /* DemoForBlogTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DemoForBlogTests.m; sourceTree = "<group>"; };
- 9030DF2A14E2BA9500325CFD /* XSDEntityNames.h */ = {isa = PBXFileReference; fileEncoding = 4; path = XSDEntityNames.h; sourceTree = "<group>"; };
+ 9030DF2A14E2BA9500325CFD /* XSDEntityNames.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XSDEntityNames.h; sourceTree = "<group>"; };
9030DF2C14E2BA9F00325CFD /* XSDEntityNames.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XSDEntityNames.m; sourceTree = "<group>"; };
9030DF2F14E2BB2E00325CFD /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = System/Library/Frameworks/CoreData.framework; sourceTree = SDKROOT; };
9030DF3614E2BD3C00325CFD /* DemoForBlogModel.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = DemoForBlogModel.xcdatamodel; sourceTree = "<group>"; };
+ 9034894914E3D74600ED8748 /* XSDDemo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = XSDDemo.h; path = ../XSDDemo.h; sourceTree = "<group>"; };
+ 9034894A14E3D74600ED8748 /* XSDDemo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = XSDDemo.m; path = ../XSDDemo.m; sourceTree = "<group>"; };
90A5D8E614E3C5D700D1DB07 /* XSDSyncOperation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XSDSyncOperation.m; sourceTree = "<group>"; };
- 90A5D8E914E3C5E300D1DB07 /* XSDSyncOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; path = XSDSyncOperation.h; sourceTree = "<group>"; };
+ 90A5D8E914E3C5E300D1DB07 /* XSDSyncOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XSDSyncOperation.h; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -147,10 +150,10 @@
9030DEF214E2AF4A00325CFD /* XSDSecondViewController.m */,
9030DEF414E2AF4A00325CFD /* second.png */,
9030DEF614E2AF4A00325CFD /* second@2x.png */,
- 9030DEF814E2AF4A00325CFD /* XSDFirstViewController.xib */,
9030DEFB14E2AF4A00325CFD /* XSDSecondViewController.xib */,
90A5D8E914E3C5E300D1DB07 /* XSDSyncOperation.h */,
90A5D8E614E3C5D700D1DB07 /* XSDSyncOperation.m */,
+ 9030DEF814E2AF4A00325CFD /* XSDFirstViewController.xib */,
9030DEDF14E2AF4900325CFD /* Supporting Files */,
);
path = DemoForBlog;
@@ -159,6 +162,8 @@
9030DEDF14E2AF4900325CFD /* Supporting Files */ = {
isa = PBXGroup;
children = (
+ 9034894914E3D74600ED8748 /* XSDDemo.h */,
+ 9034894A14E3D74600ED8748 /* XSDDemo.m */,
9030DF3514E2BD3C00325CFD /* DemoForBlogModel.xcdatamodeld */,
9030DEE014E2AF4900325CFD /* DemoForBlog-Info.plist */,
9030DEE114E2AF4900325CFD /* InfoPlist.strings */,
@@ -314,6 +319,7 @@
9030DF2D14E2BA9F00325CFD /* XSDEntityNames.m in Sources */,
9030DF3714E2BD3C00325CFD /* DemoForBlogModel.xcdatamodeld in Sources */,
90A5D8E714E3C5D700D1DB07 /* XSDSyncOperation.m in Sources */,
+ 9034894B14E3D74600ED8748 /* XSDDemo.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
8 DemoForBlog/XSDAppDelegate.h
@@ -8,7 +8,9 @@
#import <UIKit/UIKit.h>
-@interface XSDAppDelegate : UIResponder <UIApplicationDelegate, UITabBarControllerDelegate> {
+#import "XSDSyncOperation.h"
+
+@interface XSDAppDelegate : UIResponder <UIApplicationDelegate, UITabBarControllerDelegate, XSDSyncDelegate> {
NSManagedObjectContext *managedObjectContext;
}
@@ -18,4 +20,8 @@
@property (nonatomic, retain, readonly) NSManagedObjectContext *managedObjectContext;
+@property (nonatomic, retain, readonly) NSOperationQueue *operationQueue;
+
+-(void)doSync;
+
@end
View
51 DemoForBlog/XSDAppDelegate.m
@@ -16,6 +16,7 @@ @implementation XSDAppDelegate
@synthesize window = _window;
@synthesize tabBarController = _tabBarController;
+@synthesize operationQueue;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
@@ -58,6 +59,7 @@ - (void)applicationDidBecomeActive:(UIApplication *)application
/*
Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
*/
+ [self doSync];
}
- (void)applicationWillTerminate:(UIApplication *)application
@@ -84,6 +86,55 @@ - (void)tabBarController:(UITabBarController *)tabBarController didEndCustomizin
*/
#pragma mark -
+#pragma mark Sync related code
+
+-(void)doSync
+{
+ XSDSyncOperation *sync = [[XSDSyncOperation alloc]init];
+ sync.syncDelegate = self;
+
+ [sync setCompletionBlock:^{
+ [self doSync];
+ }];
+
+ if (sync)
+ [[self operationQueue] addOperation: sync];
+}
+
+- (void)syncDidSave:(NSNotification *)saveNotification {
+
+ if ([NSThread isMainThread]) {
+ [self.managedObjectContext mergeChangesFromContextDidSaveNotification:saveNotification];
+ } else {
+ [self performSelectorOnMainThread:@selector(syncDidSave:) withObject:saveNotification waitUntilDone:NO];
+ }
+}
+
+- (void)syncDidAbort
+{
+ if ([NSThread isMainThread]) {
+ UIAlertView *alert =
+ [[UIAlertView alloc] initWithTitle: @"Sync Failed"
+ message: @"An error occured while attempting to synchronize with the back-end."
+ delegate: nil
+ cancelButtonTitle: @"OK"
+ otherButtonTitles: nil];
+ [alert show];
+ } else {
+ [self performSelectorOnMainThread:@selector(syncDidAbort) withObject:nil waitUntilDone:NO];
+ }
+}
+
+- (NSOperationQueue *)operationQueue {
+ if (operationQueue == nil) {
+ operationQueue = [[NSOperationQueue alloc] init];
+ //hard coded settings, we want to make sure only one sync runs concurrently.
+ operationQueue.maxConcurrentOperationCount = 1;
+ }
+ return operationQueue;
+}
+
+#pragma mark -
#pragma mark Core Data
View
6 DemoForBlog/XSDEntityNames.m
@@ -8,9 +8,9 @@
#import "XSDEntityNames.h"
-NSString * const DEMO_ENTITY_NAME = @"Demo";
-NSString * const GRAPH_DATA_ENTITY_NAME = @"GraphData";
-NSString * const SYNC_ENTITY_NAME = @"Sync";
+NSString * const DEMO_ENTITY_NAME = @"XSDDemo";
+NSString * const GRAPH_DATA_ENTITY_NAME = @"XSDGraphData";
+NSString * const SYNC_ENTITY_NAME = @"XSDSync";
View
2  DemoForBlog/XSDSyncOperation.h
@@ -8,8 +8,6 @@
#import <Foundation/Foundation.h>
-extern NSString * const SyncOperationFinishedNotification;
-
// Protocol for the importer to communicate with its delegate.
@protocol XSDSyncDelegate <NSObject>
// Notification posted by NSManagedObjectContext when saved.
View
16 DemoForBlog/XSDSyncOperation.m
@@ -11,6 +11,7 @@
#import "XSDAppDelegate.h"
#import "XSDEntityNames.h"
#import "XSDSyncOperation.h"
+#import "XSDDemo.h"
NSString * const SyncOperationFinishedNotification = @"SyncOperationFinishedNotification";
@@ -27,11 +28,16 @@ - (BOOL)syncOnContext:(NSManagedObjectContext*) context {
[fetchRequest setEntity:entity];
NSError *error = nil;
- NSArray *demos = [context executeFetchRequest:fetchRequest error:&error];
- if (error) {
- NSLog(@"Error occured fetching demo objects: %@", error);
- return NO;
- }
+// NSArray *demos = [context executeFetchRequest:fetchRequest error:&error];
+// if (error) {
+// NSLog(@"Error occured fetching demo objects: %@", error);
+// return NO;
+// }
+
+ XSDDemo *demo = [NSEntityDescription insertNewObjectForEntityForName:DEMO_ENTITY_NAME inManagedObjectContext:context];
+ demo.name = @"Test";
+ demo.info = @"Info";
+
//Store resulting objects and broadcast the save operation to the syncdelegate.
[[NSNotificationCenter defaultCenter] addObserver:syncDelegate selector:@selector(syncDidSave:) name:NSManagedObjectContextDidSaveNotification object:context];
View
12 DemoForBlogModel.xcdatamodeld/DemoForBlogModel.xcdatamodel/contents
@@ -1,17 +1,17 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model name="" userDefinedModelVersionIdentifier="" type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="878" systemVersion="11D50" minimumToolsVersion="Automatic" macOSVersion="Automatic" iOSVersion="Automatic">
- <entity name="Demo" syncable="YES">
+ <entity name="XSDDemo" representedClassName="Demo" syncable="YES">
<attribute name="info" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="name" optional="YES" attributeType="String" syncable="YES"/>
- <relationship name="graphDataForDemo" optional="YES" toMany="YES" deletionRule="Nullify" destinationEntity="GraphData" inverseName="demoForGraphData" inverseEntity="GraphData" syncable="YES"/>
+ <relationship name="graphDataForDemo" optional="YES" toMany="YES" deletionRule="Nullify" destinationEntity="XSDGraphData" inverseName="demoForGraphData" inverseEntity="XSDGraphData" syncable="YES"/>
</entity>
- <entity name="GraphData" syncable="YES">
+ <entity name="XSDGraphData" syncable="YES">
<attribute name="x" optional="YES" attributeType="Decimal" defaultValueString="0.0" syncable="YES"/>
<attribute name="y" optional="YES" attributeType="Decimal" defaultValueString="0.0" syncable="YES"/>
- <relationship name="demoForGraphData" optional="YES" minCount="1" maxCount="1" deletionRule="Nullify" destinationEntity="Demo" inverseName="graphDataForDemo" inverseEntity="Demo" syncable="YES"/>
+ <relationship name="demoForGraphData" optional="YES" minCount="1" maxCount="1" deletionRule="Nullify" destinationEntity="XSDDemo" inverseName="graphDataForDemo" inverseEntity="XSDDemo" syncable="YES"/>
</entity>
<elements>
- <element name="Demo" positionX="160" positionY="192" width="128" height="90"/>
- <element name="GraphData" positionX="448" positionY="351" width="128" height="90"/>
+ <element name="XSDDemo" positionX="160" positionY="192" width="128" height="90"/>
+ <element name="XSDGraphData" positionX="448" positionY="351" width="128" height="90"/>
</elements>
</model>
View
27 XSDDemo.h
@@ -0,0 +1,27 @@
+//
+// Demo.h
+// DemoForBlog
+//
+// Created by Jeroen Leenarts on 09-02-12.
+// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+#import <CoreData/CoreData.h>
+
+
+@interface XSDDemo : NSManagedObject
+
+@property (nonatomic, retain) NSString * info;
+@property (nonatomic, retain) NSString * name;
+@property (nonatomic, retain) NSSet *graphDataForDemo;
+@end
+
+@interface XSDDemo (CoreDataGeneratedAccessors)
+
+- (void)addGraphDataForDemoObject:(NSManagedObject *)value;
+- (void)removeGraphDataForDemoObject:(NSManagedObject *)value;
+- (void)addGraphDataForDemo:(NSSet *)values;
+- (void)removeGraphDataForDemo:(NSSet *)values;
+
+@end
View
18 XSDDemo.m
@@ -0,0 +1,18 @@
+//
+// Demo.m
+// DemoForBlog
+//
+// Created by Jeroen Leenarts on 09-02-12.
+// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
+//
+
+#import "XSDDemo.h"
+
+
+@implementation XSDDemo
+
+@dynamic info;
+@dynamic name;
+@dynamic graphDataForDemo;
+
+@end

No commit comments for this range

Something went wrong with that request. Please try again.