[](https://travis-ci.org/Gene Myers/CoreDataLibrary)
To run the example project, clone the repo, and run pod install from the Example directory first.
CoreDataLibrary is a private CocoaPod. To install it, simply add the following line to your Podfile:
pod "CoreDataLibrary" , :git => 'git@github.com:WyldResearchLtd/CoreDataLibrary.git'Gene Myers, gene@wyldresearch.com
CoreDataLibrary is available under the MIT license. See the LICENSE file for more info.
- From Terminal, run
pod lib create CoreDataLibrary
This is the output and input required from running the above command
Configuring CoreDataLibrary template.
-------------------------------------
To get you started we need to ask a few questions, this should only take a minute.
If this is your first time we recommend running through with the guide:
- http://guides.cocoapods.org/making/using-pod-lib-create.html
( hold cmd and double click links to open in a browser. )
What language do you want to use?? [ Swift / ObjC ]
> ObjC
Would you like to include a demo application with your library? [ Yes / No ]
> Yes
Which testing frameworks will you use? [ Specta / Kiwi / None ]
> None
Would you like to do view based testing? [ Yes / No ]
> No
What is your class prefix?
> WR
- open the podfile and comment out
inherit!line - Pun
pod installfrom the Examples directory - From Terminal run
open 'CoreDataLibrary/Example/CoreDataLibrary.xcworkspace'from the root of the SRC dir
based on http://samwize.com/2014/03/27/step-by-step-guide-to-using-magicalrecord-and-mogenerator/
- add this to your podfile
pod 'MagicalRecord/Shorthand', '~> 2.2' - from the Examples dfirectory, run
pod install - Under /Pods/Development Pods/CoreDataLibrary/Classes, delete ReplaceMe.m
Right click on the Classes dir in the Project Explorer and choose Add File.
Select iOS->Source->CocoaTouch class- htis will create both the .m and .h file. Name the new files WRService The contents should be:
WRService.h
//
// WRService.h
// CoreDataLibrary Example
//
// Created by Gene Myers on 21/08/2016.
//
//
#import <Foundation/Foundation.h>
#define MR_SHORTHAND
#import "CoreData+MagicalRecord.h"
@interface WRService : NSObject
@end
WRService.h
//
// WRService.m
// CoreDataLibrary Pod
//
// Created by Gene Myers on 21/08/2016.
//
//
#import "WRService.h"
@implementation WRService
- (id)init {
self = [super init];
if (self) {
[MagicalRecord setupCoreDataStack];
}
return self;
}
- (void)dealloc
{
[ MagicalRecord cleanUp];
//http://stackoverflow.com/questions/7292119/custom-dealloc-and-arc-objective-c
//[super dealloc];//provided by the compiler
}
@end
-
In the Project Explorer, select the Pods project, then under Build Phases->Link Binaries with Libraries,
Click on the + to add the MagicalRecord.framework -
Select the CoreDataLibrary scheme and Run.
-
Select the CoreDataLibrary-Example schema, then Run
-
Install mogenerator with the command
$ sudo brew install mogenerator -
Right click on the Classes directory, select New File. Select iOS->CoreData->Data Model
Click 'Next', and make sure the CoreDataLibrary target is checked.
The Model.xcdatamodeld is placed in the Classes directory -
Add a new Entity to the model (An entity is a Table)- 'TestTable'
-
Add a new attribute to the Entity- 'testattribute' of type String
-
With the model and TestEntity selected, in the data model inspector in the right pane, add 'TestEntity' as the Class
-
Setup a target for mogenerator by running the following comand:
mogenerator --v2 -m "CoreDataLibrary/Classes/Model.xcdatamodeld" -O "CoreDataLibrary/Classes"
If successful you will see this output:2 machine files and 2 human files generated. -
In your Pods project, open your project properties and tap the “+” button at the bottom of the Targets list.
-
Add an “Aggregate” target (you’ll find it in the iOS/Other grouping). Tap Next.
-
Name the target whatever you’d like. I’ll call mine Mogenerator. Hit Done.
-
Now select the new target you just created, select the “Build Phases” tab, tap “+” to add a build phase then select “New Run Script Build Phase”.
-
Open the Run Script group that just appeared, keep the Shell at /bin/sh, and then enter the following script if you’re using Objective-C. Because the Pods projects source directory is in the Pods directory, we have to modify the script to reference the correct directory (
mogenerator --v2 -m "../../CoreDataLibrary/Classes/Model.xcdatamodeld" -O "../../CoreDataLibrary/Classes") -
Delete the files created in Step 12. Select the mogenerator target and build. This can be used regenerate all the files, if you change the model.
-
Select Pods/Development Pods/Classes dir again and right click and 'Add files to Pods', and add the 4 files.
$mogenerator --v2 -m "Example/CoreDataLibrary/Model/Host.xcdatamodeld" -O "Example/CoreDataLibrary/Model