Skip to content

Commit 4869882

Browse files
committed
Update README.md
Adds sample swift code from Tiago Alves
1 parent 08f87e1 commit 4869882

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ With the release of XCode 6 the simulator changes the name of the persistence st
4646
4747
Add this code to your iOS application:
4848
49+
### Objective C
4950
`````
5051
#if !(TARGET_OS_EMBEDDED) // This will work for Mac or Simulator but excludes physical iOS devices
5152
- (void) createCoreDataDebugProjectWithType: (NSNumber*) storeFormat storeUrl:(NSString*) storeURL modelFilePath:(NSString*) modelFilePath {
@@ -64,10 +65,33 @@ Add this code to your iOS application:
6465
#endif
6566
`````
6667
68+
### Swift
69+
70+
`````
71+
#if !(TARGET_OS_EMBEDDED)
72+
func createCoreDataDebugProjectWithType(storeFormat: NSNumber, storeURL: String, modelFilePath: String) {
73+
74+
var project:NSDictionary = [
75+
"storeFilePath": storeURL,
76+
"storeFormat" : storeFormat,
77+
"modelFilePath": modelFilePath,
78+
"v" : "1"
79+
]
80+
81+
var projectFile = "/tmp/\(NSBundle.mainBundle().infoDictionary![kCFBundleNameKey]!).cdp"
82+
83+
project.writeToFile(projectFile, atomically: true)
84+
}
85+
86+
#endif
87+
`````
88+
6789
Now call that code where you initialize your CoreData persistent store.
6890
6991
Something like this:
7092
93+
94+
### Objective C
7195
`````
7296
#if !(TARGET_OS_EMBEDDED) // This will work for Mac or Simulator but excludes physical iOS devices
7397
#ifdef DEBUG
@@ -77,6 +101,19 @@ Something like this:
77101
#endif
78102
`````
79103
104+
### Swift
105+
106+
`````
107+
108+
#if !(TARGET_OS_EMBEDDED) // This will work for Mac or Simulator but excludes physical iOS devices
109+
#if DEBUG
110+
// @(1) is NSSQLiteStoreType
111+
createCoreDataDebugProjectWithType(1, storeURL: persistentStore!.URL!.absoluteString!, modelFilePath: modelUrl.absoluteString!)
112+
#endif
113+
#endif
114+
115+
`````
116+
80117
Now you can just open the /tmp/YourAppName.cdp file and it will open CoreDataUtility with your app's data loaded.
81118
82119

0 commit comments

Comments
 (0)