pyanfield avatar pyanfield committed 102b7e4

chapter 2: adding a simple core data model to exsit project, create two Entity and relationship between them , save and read the data

Comments (0)

Files changed (19)

Binary file modified.

Add a comment to this file

BasicApplication/.DS_Store

Binary file modified.

Add a comment to this file

BasicApplication/BasicApplication.xcodeproj/project.xcworkspace/xcuserdata/pyanfield.xcuserdatad/UserInterfaceState.xcuserstate

Binary file modified.

chapter2/OrgChart/OrgChart.xcodeproj/project.pbxproj

+// !$*UTF8*$!
+{
+	archiveVersion = 1;
+	classes = {
+	};
+	objectVersion = 46;
+	objects = {
+
+/* Begin PBXBuildFile section */
+		90852879148CFE3D008F4897 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 90852878148CFE3D008F4897 /* UIKit.framework */; };
+		9085287B148CFE3D008F4897 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9085287A148CFE3D008F4897 /* Foundation.framework */; };
+		9085287D148CFE3D008F4897 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9085287C148CFE3D008F4897 /* CoreGraphics.framework */; };
+		90852883148CFE3D008F4897 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 90852881148CFE3D008F4897 /* InfoPlist.strings */; };
+		90852885148CFE3D008F4897 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 90852884148CFE3D008F4897 /* main.m */; };
+		90852889148CFE3D008F4897 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 90852888148CFE3D008F4897 /* AppDelegate.m */; };
+		9085288C148CFE3D008F4897 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9085288B148CFE3D008F4897 /* ViewController.m */; };
+		9085288F148CFE3D008F4897 /* ViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 9085288D148CFE3D008F4897 /* ViewController.xib */; };
+		90852896148CFE6F008F4897 /* CoreData.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 90852895148CFE6F008F4897 /* CoreData.framework */; };
+		90852899148CFEB6008F4897 /* OrgChart.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 90852897148CFEB6008F4897 /* OrgChart.xcdatamodeld */; };
+/* End PBXBuildFile section */
+
+/* Begin PBXFileReference section */
+		90852874148CFE3D008F4897 /* OrgChart.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = OrgChart.app; sourceTree = BUILT_PRODUCTS_DIR; };
+		90852878148CFE3D008F4897 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
+		9085287A148CFE3D008F4897 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
+		9085287C148CFE3D008F4897 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
+		90852880148CFE3D008F4897 /* OrgChart-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "OrgChart-Info.plist"; sourceTree = "<group>"; };
+		90852882148CFE3D008F4897 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
+		90852884148CFE3D008F4897 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
+		90852886148CFE3D008F4897 /* OrgChart-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "OrgChart-Prefix.pch"; sourceTree = "<group>"; };
+		90852887148CFE3D008F4897 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
+		90852888148CFE3D008F4897 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
+		9085288A148CFE3D008F4897 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = "<group>"; };
+		9085288B148CFE3D008F4897 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = "<group>"; };
+		9085288E148CFE3D008F4897 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/ViewController.xib; sourceTree = "<group>"; };
+		90852895148CFE6F008F4897 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = System/Library/Frameworks/CoreData.framework; sourceTree = SDKROOT; };
+		90852898148CFEB6008F4897 /* OrgChart.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = OrgChart.xcdatamodel; sourceTree = "<group>"; };
+/* End PBXFileReference section */
+
+/* Begin PBXFrameworksBuildPhase section */
+		90852871148CFE3D008F4897 /* Frameworks */ = {
+			isa = PBXFrameworksBuildPhase;
+			buildActionMask = 2147483647;
+			files = (
+				90852896148CFE6F008F4897 /* CoreData.framework in Frameworks */,
+				90852879148CFE3D008F4897 /* UIKit.framework in Frameworks */,
+				9085287B148CFE3D008F4897 /* Foundation.framework in Frameworks */,
+				9085287D148CFE3D008F4897 /* CoreGraphics.framework in Frameworks */,
+			);
+			runOnlyForDeploymentPostprocessing = 0;
+		};
+/* End PBXFrameworksBuildPhase section */
+
+/* Begin PBXGroup section */
+		90852869148CFE3C008F4897 = {
+			isa = PBXGroup;
+			children = (
+				9085287E148CFE3D008F4897 /* OrgChart */,
+				90852877148CFE3D008F4897 /* Frameworks */,
+				90852875148CFE3D008F4897 /* Products */,
+			);
+			sourceTree = "<group>";
+		};
+		90852875148CFE3D008F4897 /* Products */ = {
+			isa = PBXGroup;
+			children = (
+				90852874148CFE3D008F4897 /* OrgChart.app */,
+			);
+			name = Products;
+			sourceTree = "<group>";
+		};
+		90852877148CFE3D008F4897 /* Frameworks */ = {
+			isa = PBXGroup;
+			children = (
+				90852895148CFE6F008F4897 /* CoreData.framework */,
+				90852878148CFE3D008F4897 /* UIKit.framework */,
+				9085287A148CFE3D008F4897 /* Foundation.framework */,
+				9085287C148CFE3D008F4897 /* CoreGraphics.framework */,
+			);
+			name = Frameworks;
+			sourceTree = "<group>";
+		};
+		9085287E148CFE3D008F4897 /* OrgChart */ = {
+			isa = PBXGroup;
+			children = (
+				90852887148CFE3D008F4897 /* AppDelegate.h */,
+				90852888148CFE3D008F4897 /* AppDelegate.m */,
+				9085288A148CFE3D008F4897 /* ViewController.h */,
+				9085288B148CFE3D008F4897 /* ViewController.m */,
+				9085288D148CFE3D008F4897 /* ViewController.xib */,
+				9085287F148CFE3D008F4897 /* Supporting Files */,
+			);
+			path = OrgChart;
+			sourceTree = "<group>";
+		};
+		9085287F148CFE3D008F4897 /* Supporting Files */ = {
+			isa = PBXGroup;
+			children = (
+				90852897148CFEB6008F4897 /* OrgChart.xcdatamodeld */,
+				90852880148CFE3D008F4897 /* OrgChart-Info.plist */,
+				90852881148CFE3D008F4897 /* InfoPlist.strings */,
+				90852884148CFE3D008F4897 /* main.m */,
+				90852886148CFE3D008F4897 /* OrgChart-Prefix.pch */,
+			);
+			name = "Supporting Files";
+			sourceTree = "<group>";
+		};
+/* End PBXGroup section */
+
+/* Begin PBXNativeTarget section */
+		90852873148CFE3D008F4897 /* OrgChart */ = {
+			isa = PBXNativeTarget;
+			buildConfigurationList = 90852892148CFE3D008F4897 /* Build configuration list for PBXNativeTarget "OrgChart" */;
+			buildPhases = (
+				90852870148CFE3D008F4897 /* Sources */,
+				90852871148CFE3D008F4897 /* Frameworks */,
+				90852872148CFE3D008F4897 /* Resources */,
+			);
+			buildRules = (
+			);
+			dependencies = (
+			);
+			name = OrgChart;
+			productName = OrgChart;
+			productReference = 90852874148CFE3D008F4897 /* OrgChart.app */;
+			productType = "com.apple.product-type.application";
+		};
+/* End PBXNativeTarget section */
+
+/* Begin PBXProject section */
+		9085286B148CFE3C008F4897 /* Project object */ = {
+			isa = PBXProject;
+			attributes = {
+				LastUpgradeCheck = 0420;
+				ORGANIZATIONNAME = pyanfield;
+			};
+			buildConfigurationList = 9085286E148CFE3C008F4897 /* Build configuration list for PBXProject "OrgChart" */;
+			compatibilityVersion = "Xcode 3.2";
+			developmentRegion = English;
+			hasScannedForEncodings = 0;
+			knownRegions = (
+				en,
+			);
+			mainGroup = 90852869148CFE3C008F4897;
+			productRefGroup = 90852875148CFE3D008F4897 /* Products */;
+			projectDirPath = "";
+			projectRoot = "";
+			targets = (
+				90852873148CFE3D008F4897 /* OrgChart */,
+			);
+		};
+/* End PBXProject section */
+
+/* Begin PBXResourcesBuildPhase section */
+		90852872148CFE3D008F4897 /* Resources */ = {
+			isa = PBXResourcesBuildPhase;
+			buildActionMask = 2147483647;
+			files = (
+				90852883148CFE3D008F4897 /* InfoPlist.strings in Resources */,
+				9085288F148CFE3D008F4897 /* ViewController.xib in Resources */,
+			);
+			runOnlyForDeploymentPostprocessing = 0;
+		};
+/* End PBXResourcesBuildPhase section */
+
+/* Begin PBXSourcesBuildPhase section */
+		90852870148CFE3D008F4897 /* Sources */ = {
+			isa = PBXSourcesBuildPhase;
+			buildActionMask = 2147483647;
+			files = (
+				90852885148CFE3D008F4897 /* main.m in Sources */,
+				90852889148CFE3D008F4897 /* AppDelegate.m in Sources */,
+				9085288C148CFE3D008F4897 /* ViewController.m in Sources */,
+				90852899148CFEB6008F4897 /* OrgChart.xcdatamodeld in Sources */,
+			);
+			runOnlyForDeploymentPostprocessing = 0;
+		};
+/* End PBXSourcesBuildPhase section */
+
+/* Begin PBXVariantGroup section */
+		90852881148CFE3D008F4897 /* InfoPlist.strings */ = {
+			isa = PBXVariantGroup;
+			children = (
+				90852882148CFE3D008F4897 /* en */,
+			);
+			name = InfoPlist.strings;
+			sourceTree = "<group>";
+		};
+		9085288D148CFE3D008F4897 /* ViewController.xib */ = {
+			isa = PBXVariantGroup;
+			children = (
+				9085288E148CFE3D008F4897 /* en */,
+			);
+			name = ViewController.xib;
+			sourceTree = "<group>";
+		};
+/* End PBXVariantGroup section */
+
+/* Begin XCBuildConfiguration section */
+		90852890148CFE3D008F4897 /* Debug */ = {
+			isa = XCBuildConfiguration;
+			buildSettings = {
+				ALWAYS_SEARCH_USER_PATHS = NO;
+				ARCHS = "$(ARCHS_STANDARD_32_BIT)";
+				CLANG_ENABLE_OBJC_ARC = YES;
+				"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
+				COPY_PHASE_STRIP = NO;
+				GCC_C_LANGUAGE_STANDARD = gnu99;
+				GCC_DYNAMIC_NO_PIC = NO;
+				GCC_OPTIMIZATION_LEVEL = 0;
+				GCC_PREPROCESSOR_DEFINITIONS = (
+					"DEBUG=1",
+					"$(inherited)",
+				);
+				GCC_SYMBOLS_PRIVATE_EXTERN = NO;
+				GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
+				GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
+				GCC_WARN_ABOUT_RETURN_TYPE = YES;
+				GCC_WARN_UNUSED_VARIABLE = YES;
+				IPHONEOS_DEPLOYMENT_TARGET = 5.0;
+				SDKROOT = iphoneos;
+			};
+			name = Debug;
+		};
+		90852891148CFE3D008F4897 /* Release */ = {
+			isa = XCBuildConfiguration;
+			buildSettings = {
+				ALWAYS_SEARCH_USER_PATHS = NO;
+				ARCHS = "$(ARCHS_STANDARD_32_BIT)";
+				CLANG_ENABLE_OBJC_ARC = YES;
+				"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
+				COPY_PHASE_STRIP = YES;
+				GCC_C_LANGUAGE_STANDARD = gnu99;
+				GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
+				GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
+				GCC_WARN_ABOUT_RETURN_TYPE = YES;
+				GCC_WARN_UNUSED_VARIABLE = YES;
+				IPHONEOS_DEPLOYMENT_TARGET = 5.0;
+				OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1";
+				SDKROOT = iphoneos;
+				VALIDATE_PRODUCT = YES;
+			};
+			name = Release;
+		};
+		90852893148CFE3D008F4897 /* Debug */ = {
+			isa = XCBuildConfiguration;
+			buildSettings = {
+				GCC_PRECOMPILE_PREFIX_HEADER = YES;
+				GCC_PREFIX_HEADER = "OrgChart/OrgChart-Prefix.pch";
+				INFOPLIST_FILE = "OrgChart/OrgChart-Info.plist";
+				PRODUCT_NAME = "$(TARGET_NAME)";
+				WRAPPER_EXTENSION = app;
+			};
+			name = Debug;
+		};
+		90852894148CFE3D008F4897 /* Release */ = {
+			isa = XCBuildConfiguration;
+			buildSettings = {
+				GCC_PRECOMPILE_PREFIX_HEADER = YES;
+				GCC_PREFIX_HEADER = "OrgChart/OrgChart-Prefix.pch";
+				INFOPLIST_FILE = "OrgChart/OrgChart-Info.plist";
+				PRODUCT_NAME = "$(TARGET_NAME)";
+				WRAPPER_EXTENSION = app;
+			};
+			name = Release;
+		};
+/* End XCBuildConfiguration section */
+
+/* Begin XCConfigurationList section */
+		9085286E148CFE3C008F4897 /* Build configuration list for PBXProject "OrgChart" */ = {
+			isa = XCConfigurationList;
+			buildConfigurations = (
+				90852890148CFE3D008F4897 /* Debug */,
+				90852891148CFE3D008F4897 /* Release */,
+			);
+			defaultConfigurationIsVisible = 0;
+			defaultConfigurationName = Release;
+		};
+		90852892148CFE3D008F4897 /* Build configuration list for PBXNativeTarget "OrgChart" */ = {
+			isa = XCConfigurationList;
+			buildConfigurations = (
+				90852893148CFE3D008F4897 /* Debug */,
+				90852894148CFE3D008F4897 /* Release */,
+			);
+			defaultConfigurationIsVisible = 0;
+		};
+/* End XCConfigurationList section */
+
+/* Begin XCVersionGroup section */
+		90852897148CFEB6008F4897 /* OrgChart.xcdatamodeld */ = {
+			isa = XCVersionGroup;
+			children = (
+				90852898148CFEB6008F4897 /* OrgChart.xcdatamodel */,
+			);
+			currentVersion = 90852898148CFEB6008F4897 /* OrgChart.xcdatamodel */;
+			path = OrgChart.xcdatamodeld;
+			sourceTree = "<group>";
+			versionGroupType = wrapper.xcdatamodel;
+		};
+/* End XCVersionGroup section */
+	};
+	rootObject = 9085286B148CFE3C008F4897 /* Project object */;
+}

chapter2/OrgChart/OrgChart.xcodeproj/project.xcworkspace/contents.xcworkspacedata

+<?xml version="1.0" encoding="UTF-8"?>
+<Workspace
+   version = "1.0">
+   <FileRef
+      location = "self:OrgChart.xcodeproj">
+   </FileRef>
+</Workspace>
Add a comment to this file

chapter2/OrgChart/OrgChart.xcodeproj/project.xcworkspace/xcuserdata/pyanfield.xcuserdatad/UserInterfaceState.xcuserstate

Binary file added.

chapter2/OrgChart/OrgChart.xcodeproj/xcuserdata/pyanfield.xcuserdatad/xcschemes/OrgChart.xcscheme

+<?xml version="1.0" encoding="UTF-8"?>
+<Scheme
+   version = "1.3">
+   <BuildAction
+      parallelizeBuildables = "YES"
+      buildImplicitDependencies = "YES">
+      <BuildActionEntries>
+         <BuildActionEntry
+            buildForTesting = "YES"
+            buildForRunning = "YES"
+            buildForProfiling = "YES"
+            buildForArchiving = "YES"
+            buildForAnalyzing = "YES">
+            <BuildableReference
+               BuildableIdentifier = "primary"
+               BlueprintIdentifier = "90852873148CFE3D008F4897"
+               BuildableName = "OrgChart.app"
+               BlueprintName = "OrgChart"
+               ReferencedContainer = "container:OrgChart.xcodeproj">
+            </BuildableReference>
+         </BuildActionEntry>
+      </BuildActionEntries>
+   </BuildAction>
+   <TestAction
+      selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.GDB"
+      selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.GDB"
+      shouldUseLaunchSchemeArgsEnv = "YES"
+      buildConfiguration = "Debug">
+      <Testables>
+      </Testables>
+      <MacroExpansion>
+         <BuildableReference
+            BuildableIdentifier = "primary"
+            BlueprintIdentifier = "90852873148CFE3D008F4897"
+            BuildableName = "OrgChart.app"
+            BlueprintName = "OrgChart"
+            ReferencedContainer = "container:OrgChart.xcodeproj">
+         </BuildableReference>
+      </MacroExpansion>
+   </TestAction>
+   <LaunchAction
+      selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.GDB"
+      selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.GDB"
+      launchStyle = "0"
+      useCustomWorkingDirectory = "NO"
+      buildConfiguration = "Debug"
+      debugDocumentVersioning = "YES"
+      allowLocationSimulation = "YES">
+      <BuildableProductRunnable>
+         <BuildableReference
+            BuildableIdentifier = "primary"
+            BlueprintIdentifier = "90852873148CFE3D008F4897"
+            BuildableName = "OrgChart.app"
+            BlueprintName = "OrgChart"
+            ReferencedContainer = "container:OrgChart.xcodeproj">
+         </BuildableReference>
+      </BuildableProductRunnable>
+      <AdditionalOptions>
+      </AdditionalOptions>
+   </LaunchAction>
+   <ProfileAction
+      shouldUseLaunchSchemeArgsEnv = "YES"
+      savedToolIdentifier = ""
+      useCustomWorkingDirectory = "NO"
+      buildConfiguration = "Release"
+      debugDocumentVersioning = "YES">
+      <BuildableProductRunnable>
+         <BuildableReference
+            BuildableIdentifier = "primary"
+            BlueprintIdentifier = "90852873148CFE3D008F4897"
+            BuildableName = "OrgChart.app"
+            BlueprintName = "OrgChart"
+            ReferencedContainer = "container:OrgChart.xcodeproj">
+         </BuildableReference>
+      </BuildableProductRunnable>
+   </ProfileAction>
+   <AnalyzeAction
+      buildConfiguration = "Debug">
+   </AnalyzeAction>
+   <ArchiveAction
+      buildConfiguration = "Release"
+      revealArchiveInOrganizer = "YES">
+   </ArchiveAction>
+</Scheme>

chapter2/OrgChart/OrgChart.xcodeproj/xcuserdata/pyanfield.xcuserdatad/xcschemes/xcschememanagement.plist

+<?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>OrgChart.xcscheme</key>
+		<dict>
+			<key>orderHint</key>
+			<integer>0</integer>
+		</dict>
+	</dict>
+	<key>SuppressBuildableAutocreation</key>
+	<dict>
+		<key>90852873148CFE3D008F4897</key>
+		<dict>
+			<key>primary</key>
+			<true/>
+		</dict>
+	</dict>
+</dict>
+</plist>

chapter2/OrgChart/OrgChart/AppDelegate.h

+//
+//  AppDelegate.h
+//  OrgChart
+//
+//  Created by han pyanfield on 11-12-5.
+//  Copyright (c) 2011年 pyanfield. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+#import <CoreData/CoreData.h>
+
+@class ViewController;
+
+@interface AppDelegate : UIResponder <UIApplicationDelegate>
+
+@property (strong, nonatomic) UIWindow *window;
+
+@property (strong, nonatomic) ViewController *viewController;
+
+//for core data
+@property (nonatomic,strong,readonly) NSManagedObjectContext *managedObjectContext;
+@property (nonatomic,strong,readonly) NSManagedObjectModel *managedObjectModel;
+@property (nonatomic,strong,readonly) NSPersistentStoreCoordinator *persistentStoreCoordinator;
+
+- (void)createData;
+- (void)displayPerson:(NSManagedObject*)person withIndentation:(NSString*)indentation;
+- (void)readData;
+@end

chapter2/OrgChart/OrgChart/AppDelegate.m

+//
+//  AppDelegate.m
+//  OrgChart
+//
+//  Created by han pyanfield on 11-12-5.
+//  Copyright (c) 2011年 pyanfield. All rights reserved.
+//
+
+#import "AppDelegate.h"
+
+#import "ViewController.h"
+
+@implementation AppDelegate
+
+@synthesize window = _window;
+@synthesize viewController = _viewController;
+
+@synthesize managedObjectModel = _managedObjectModel;
+@synthesize managedObjectContext = _managedObjectContext;
+@synthesize persistentStoreCoordinator = _persistentStoreCoordinator;
+
+- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
+{
+    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
+    // Override point for customization after application launch.
+    self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
+    self.window.rootViewController = self.viewController;
+    [self.window makeKeyAndVisible];
+    
+    // for core data to create demo data
+    //[self createData];
+    // for reading the data which saved before
+    [self readData];
+    return YES;
+}
+//p67 create demo data 
+- (void)createData
+{
+    NSManagedObjectContext *content = [self managedObjectContext];
+    //for Organization
+    NSEntityDescription *orgEntity = [NSEntityDescription entityForName:@"Organization" inManagedObjectContext:content];
+    NSManagedObject *organization = [NSEntityDescription insertNewObjectForEntityForName:[orgEntity name] inManagedObjectContext:content];
+    [organization setValue:@"MyCompany" forKey:@"name"];
+    int orgId = [organization hash];
+    [organization setValue:[NSNumber numberWithInt:orgId] forKey:@"id"];
+    //for Person
+    NSEntityDescription *personEntity = [NSEntityDescription entityForName:@"Person" inManagedObjectContext:content];
+    NSManagedObject *john = [NSEntityDescription insertNewObjectForEntityForName:[personEntity name] inManagedObjectContext:content];
+    [john setValue:[NSNumber numberWithInt:[john hash]] forKey:@"id"];
+    [john setValue:@"John" forKey:@"name"];
+    NSManagedObject *jane = [NSEntityDescription insertNewObjectForEntityForName:[personEntity name] inManagedObjectContext:content];
+    [jane setValue:[NSNumber numberWithInt:[jane hash]] forKey:@"id"];
+    [jane setValue:@"Jane" forKey:@"name"];
+    NSManagedObject *bill = [NSEntityDescription insertNewObjectForEntityForName:[personEntity name] inManagedObjectContext:content];
+    [bill setValue:[NSNumber numberWithInt:[bill hash]] forKey:@"id"];
+    [bill setValue:@"Bill" forKey:@"name"];
+    // for relationship
+    [organization setValue:john forKey:@"leader"];
+    NSMutableSet *johnEmployees = [john mutableSetValueForKey:@"employees"];
+    [johnEmployees addObject:jane];
+    [johnEmployees addObject:bill];
+    
+    //commit changes
+    NSError *error = nil;
+    if(![content save:&error])
+    {
+        NSLog(@"Unresolved error %@,%@",error,[error userInfo]);
+        abort();
+    }
+    
+    
+}
+
+- (void)displayPerson:(NSManagedObject*)person withIndentation:(NSString*)indentation
+{
+    
+    NSLog(@"%@Name : %@",indentation,[person valueForKey:@"name"]);
+    //INcrease the indentation for sub-levels
+    indentation = [NSString stringWithFormat:@"%@   ",indentation];
+    
+    NSSet *employees = [person valueForKey:@"employees"];
+    id employee;
+    NSEnumerator *it = [employees objectEnumerator];
+    while ((employee = [it nextObject])!=nil) {
+        [self displayPerson:employee withIndentation:indentation];
+    }
+}
+
+- (void)readData
+{
+    NSManagedObjectContext *context = [self managedObjectContext];
+    NSEntityDescription *orgEntity = [NSEntityDescription entityForName:@"Organization" inManagedObjectContext:context];
+    
+    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
+    [fetchRequest setEntity:orgEntity];
+    NSArray *organizations = [context executeFetchRequest:fetchRequest error:nil];
+    id organization;
+    NSEnumerator *it = [organizations objectEnumerator];
+    while ((organization = [it nextObject])!= nil) {
+        NSLog(@"Organization : %@",[organization valueForKey:@"name"]);
+        NSManagedObject *leader = [organization valueForKey:@"leader"];
+        [self displayPerson:leader withIndentation:@"   "];
+    }
+}
+
+- (void)applicationWillResignActive:(UIApplication *)application
+{
+    /*
+     Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
+     Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
+     */
+}
+
+- (void)applicationDidEnterBackground:(UIApplication *)application
+{
+    /*
+     Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
+     If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
+     */
+}
+
+- (void)applicationWillEnterForeground:(UIApplication *)application
+{
+    /*
+     Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
+     */
+}
+
+- (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.
+     */
+}
+
+- (void)applicationWillTerminate:(UIApplication *)application
+{
+    /*
+     Called when the application is about to terminate.
+     Save data if appropriate.
+     See also applicationDidEnterBackground:.
+     */
+}
+
+//for core data
+#pragma mark - Core Data Stack
+
+- (NSManagedObjectModel*)managedObjectModel
+{
+    if(_managedObjectModel != nil)
+    {
+        return _managedObjectModel;
+    }
+    
+    _managedObjectModel = [NSManagedObjectModel mergedModelFromBundles:nil];
+    return _managedObjectModel;
+}
+
+- (NSPersistentStoreCoordinator*)persistentStoreCoordinator
+{
+    if (_persistentStoreCoordinator != nil) {
+        return _persistentStoreCoordinator;
+    }
+    
+    NSString *dir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
+    NSURL *storeURL = [NSURL fileURLWithPath:[dir stringByAppendingPathComponent:@"OrgChart.sqlite"]];
+    
+    NSError *error = nil;
+    _persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
+    
+    if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) {
+        NSLog(@"Unresolved error %@, %@",error,[error userInfo]);
+        abort();
+    }
+    return _persistentStoreCoordinator;
+}
+
+- (NSManagedObjectContext*)managedObjectContext
+{
+    if (_managedObjectContext != nil) {
+        return _managedObjectContext;
+    }
+    
+    NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator];
+    if (coordinator!=nil) {
+        _managedObjectContext = [[NSManagedObjectContext alloc] init];
+        _managedObjectContext.persistentStoreCoordinator = coordinator;
+    }
+    return _managedObjectContext;
+}
+
+@end

chapter2/OrgChart/OrgChart/OrgChart-Info.plist

+<?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>CFBundleDevelopmentRegion</key>
+	<string>en</string>
+	<key>CFBundleDisplayName</key>
+	<string>${PRODUCT_NAME}</string>
+	<key>CFBundleExecutable</key>
+	<string>${EXECUTABLE_NAME}</string>
+	<key>CFBundleIconFiles</key>
+	<array/>
+	<key>CFBundleIdentifier</key>
+	<string>test.pyanfield.${PRODUCT_NAME:rfc1034identifier}</string>
+	<key>CFBundleInfoDictionaryVersion</key>
+	<string>6.0</string>
+	<key>CFBundleName</key>
+	<string>${PRODUCT_NAME}</string>
+	<key>CFBundlePackageType</key>
+	<string>APPL</string>
+	<key>CFBundleShortVersionString</key>
+	<string>1.0</string>
+	<key>CFBundleSignature</key>
+	<string>????</string>
+	<key>CFBundleVersion</key>
+	<string>1.0</string>
+	<key>LSRequiresIPhoneOS</key>
+	<true/>
+	<key>UIRequiredDeviceCapabilities</key>
+	<array>
+		<string>armv7</string>
+	</array>
+	<key>UISupportedInterfaceOrientations</key>
+	<array>
+		<string>UIInterfaceOrientationPortrait</string>
+		<string>UIInterfaceOrientationLandscapeLeft</string>
+		<string>UIInterfaceOrientationLandscapeRight</string>
+	</array>
+</dict>
+</plist>

chapter2/OrgChart/OrgChart/OrgChart-Prefix.pch

+//
+// Prefix header for all source files of the 'OrgChart' target in the 'OrgChart' project
+//
+
+#import <Availability.h>
+
+#ifndef __IPHONE_4_0
+#warning "This project uses features only available in iOS SDK 4.0 and later."
+#endif
+
+#ifdef __OBJC__
+    #import <UIKit/UIKit.h>
+    #import <Foundation/Foundation.h>
+#endif

chapter2/OrgChart/OrgChart/OrgChart.xcdatamodeld/.xccurrentversion

+<?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>_XCCurrentVersionName</key>
+	<string>OrgChart.xcdatamodel</string>
+</dict>
+</plist>

chapter2/OrgChart/OrgChart/OrgChart.xcdatamodeld/OrgChart.xcdatamodel/contents

+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<model name="" userDefinedModelVersionIdentifier="" type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="872" systemVersion="11C74" minimumToolsVersion="Automatic" macOSVersion="Automatic" iOSVersion="Automatic">
+    <entity name="Organization" syncable="YES">
+        <attribute name="id" optional="YES" attributeType="Integer 16" defaultValueString="0" syncable="YES"/>
+        <attribute name="name" optional="YES" attributeType="String" syncable="YES"/>
+        <relationship name="leader" optional="YES" minCount="1" maxCount="1" deletionRule="Nullify" destinationEntity="Person" syncable="YES"/>
+    </entity>
+    <entity name="Person" syncable="YES">
+        <attribute name="id" optional="YES" attributeType="Integer 16" defaultValueString="0" syncable="YES"/>
+        <attribute name="name" optional="YES" attributeType="String" syncable="YES"/>
+        <relationship name="employees" optional="YES" toMany="YES" deletionRule="Nullify" destinationEntity="Person" syncable="YES"/>
+    </entity>
+    <elements>
+        <element name="Organization" positionX="-63" positionY="-27" width="128" height="90"/>
+        <element name="Person" positionX="223" positionY="-45" width="128" height="90"/>
+    </elements>
+</model>

chapter2/OrgChart/OrgChart/ViewController.h

+//
+//  ViewController.h
+//  OrgChart
+//
+//  Created by han pyanfield on 11-12-5.
+//  Copyright (c) 2011年 pyanfield. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+@interface ViewController : UIViewController
+
+@end

chapter2/OrgChart/OrgChart/ViewController.m

+//
+//  ViewController.m
+//  OrgChart
+//
+//  Created by han pyanfield on 11-12-5.
+//  Copyright (c) 2011年 pyanfield. All rights reserved.
+//
+
+#import "ViewController.h"
+
+@implementation ViewController
+
+- (void)didReceiveMemoryWarning
+{
+    [super didReceiveMemoryWarning];
+    // Release any cached data, images, etc that aren't in use.
+}
+
+#pragma mark - View lifecycle
+
+- (void)viewDidLoad
+{
+    [super viewDidLoad];
+	// Do any additional setup after loading the view, typically from a nib.
+}
+
+- (void)viewDidUnload
+{
+    [super viewDidUnload];
+    // Release any retained subviews of the main view.
+    // e.g. self.myOutlet = nil;
+}
+
+- (void)viewWillAppear:(BOOL)animated
+{
+    [super viewWillAppear:animated];
+}
+
+- (void)viewDidAppear:(BOOL)animated
+{
+    [super viewDidAppear:animated];
+}
+
+- (void)viewWillDisappear:(BOOL)animated
+{
+	[super viewWillDisappear:animated];
+}
+
+- (void)viewDidDisappear:(BOOL)animated
+{
+	[super viewDidDisappear:animated];
+}
+
+- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
+{
+    // Return YES for supported orientations
+    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
+}
+
+@end

chapter2/OrgChart/OrgChart/en.lproj/InfoPlist.strings

+/* Localized versions of Info.plist keys */
+

chapter2/OrgChart/OrgChart/en.lproj/ViewController.xib

+<?xml version="1.0" encoding="UTF-8"?>
+<archive type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="8.00">
+	<data>
+		<int key="IBDocument.SystemTarget">1280</int>
+		<string key="IBDocument.SystemVersion">11C25</string>
+		<string key="IBDocument.InterfaceBuilderVersion">1919</string>
+		<string key="IBDocument.AppKitVersion">1138.11</string>
+		<string key="IBDocument.HIToolboxVersion">566.00</string>
+		<object class="NSMutableDictionary" key="IBDocument.PluginVersions">
+			<string key="NS.key.0">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+			<string key="NS.object.0">916</string>
+		</object>
+		<array key="IBDocument.IntegratedClassDependencies">
+			<string>IBProxyObject</string>
+			<string>IBUIView</string>
+		</array>
+		<array key="IBDocument.PluginDependencies">
+			<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+		</array>
+		<object class="NSMutableDictionary" key="IBDocument.Metadata">
+			<string key="NS.key.0">PluginDependencyRecalculationVersion</string>
+			<integer value="1" key="NS.object.0"/>
+		</object>
+		<array class="NSMutableArray" key="IBDocument.RootObjects" id="1000">
+			<object class="IBProxyObject" id="372490531">
+				<string key="IBProxiedObjectIdentifier">IBFilesOwner</string>
+				<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
+			</object>
+			<object class="IBProxyObject" id="843779117">
+				<string key="IBProxiedObjectIdentifier">IBFirstResponder</string>
+				<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
+			</object>
+			<object class="IBUIView" id="774585933">
+				<reference key="NSNextResponder"/>
+				<int key="NSvFlags">274</int>
+				<string key="NSFrame">{{0, 20}, {320, 460}}</string>
+				<reference key="NSSuperview"/>
+				<reference key="NSWindow"/>
+				<object class="NSColor" key="IBUIBackgroundColor">
+					<int key="NSColorSpace">3</int>
+					<bytes key="NSWhite">MC43NQA</bytes>
+					<object class="NSColorSpace" key="NSCustomColorSpace">
+						<int key="NSID">2</int>
+					</object>
+				</object>
+				<bool key="IBUIClearsContextBeforeDrawing">NO</bool>
+				<object class="IBUISimulatedStatusBarMetrics" key="IBUISimulatedStatusBarMetrics"/>
+				<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
+			</object>
+		</array>
+		<object class="IBObjectContainer" key="IBDocument.Objects">
+			<array class="NSMutableArray" key="connectionRecords">
+				<object class="IBConnectionRecord">
+					<object class="IBCocoaTouchOutletConnection" key="connection">
+						<string key="label">view</string>
+						<reference key="source" ref="372490531"/>
+						<reference key="destination" ref="774585933"/>
+					</object>
+					<int key="connectionID">7</int>
+				</object>
+			</array>
+			<object class="IBMutableOrderedSet" key="objectRecords">
+				<array key="orderedObjects">
+					<object class="IBObjectRecord">
+						<int key="objectID">0</int>
+						<array key="object" id="0"/>
+						<reference key="children" ref="1000"/>
+						<nil key="parent"/>
+					</object>
+					<object class="IBObjectRecord">
+						<int key="objectID">-1</int>
+						<reference key="object" ref="372490531"/>
+						<reference key="parent" ref="0"/>
+						<string key="objectName">File's Owner</string>
+					</object>
+					<object class="IBObjectRecord">
+						<int key="objectID">-2</int>
+						<reference key="object" ref="843779117"/>
+						<reference key="parent" ref="0"/>
+					</object>
+					<object class="IBObjectRecord">
+						<int key="objectID">6</int>
+						<reference key="object" ref="774585933"/>
+						<reference key="parent" ref="0"/>
+					</object>
+				</array>
+			</object>
+			<dictionary class="NSMutableDictionary" key="flattenedProperties">
+				<string key="-1.CustomClassName">ViewController</string>
+				<string key="-1.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+				<string key="-2.CustomClassName">UIResponder</string>
+				<string key="-2.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+				<string key="6.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+			</dictionary>
+			<dictionary class="NSMutableDictionary" key="unlocalizedProperties"/>
+			<nil key="activeLocalization"/>
+			<dictionary class="NSMutableDictionary" key="localizations"/>
+			<nil key="sourceID"/>
+			<int key="maxID">7</int>
+		</object>
+		<object class="IBClassDescriber" key="IBDocument.Classes">
+			<array class="NSMutableArray" key="referencedPartialClassDescriptions">
+				<object class="IBPartialClassDescription">
+					<string key="className">ViewController</string>
+					<string key="superclassName">UIViewController</string>
+					<object class="IBClassDescriptionSource" key="sourceIdentifier">
+						<string key="majorKey">IBProjectSource</string>
+						<string key="minorKey">./Classes/ViewController.h</string>
+					</object>
+				</object>
+			</array>
+		</object>
+		<int key="IBDocument.localizationMode">0</int>
+		<string key="IBDocument.TargetRuntimeIdentifier">IBCocoaTouchFramework</string>
+		<bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool>
+		<int key="IBDocument.defaultPropertyAccessControl">3</int>
+		<string key="IBCocoaTouchPluginVersion">916</string>
+	</data>
+</archive>

chapter2/OrgChart/OrgChart/main.m

+//
+//  main.m
+//  OrgChart
+//
+//  Created by han pyanfield on 11-12-5.
+//  Copyright (c) 2011年 pyanfield. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+#import "AppDelegate.h"
+
+int main(int argc, char *argv[])
+{
+    @autoreleasepool {
+        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
+    }
+}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.