├── .clang-format ├── .cocoadocs.yml ├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── CONTRIBUTING.md ├── Docs ├── Creating-Entities.md ├── Deleting-Entities.md ├── Fetching-Entities.md ├── Getting-Started.md ├── Importing-Data.md ├── Installing-MagicalRecord.md ├── Logging.md ├── Other-Resources.md ├── Saving-Entities.md ├── Threads.md └── Working-with-Managed-Object-Contexts.md ├── LICENSE ├── MagicalRecord.podspec ├── MagicalRecord.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ └── contents.xcworkspacedata └── xcshareddata │ └── xcschemes │ ├── MagicalRecord for OS X.xcscheme │ ├── MagicalRecord for iOS.xcscheme │ ├── MagicalRecord for tvOS.xcscheme │ ├── libMagicalRecord for OS X.xcscheme │ ├── libMagicalRecord for iOS.xcscheme │ └── libMagicalRecord for tvOS.xcscheme ├── MagicalRecord ├── Categories │ ├── DataImport │ │ ├── MagicalImportFunctions.h │ │ ├── MagicalImportFunctions.m │ │ ├── NSAttributeDescription+MagicalDataImport.h │ │ ├── NSAttributeDescription+MagicalDataImport.m │ │ ├── NSEntityDescription+MagicalDataImport.h │ │ ├── NSEntityDescription+MagicalDataImport.m │ │ ├── NSNumber+MagicalDataImport.h │ │ ├── NSNumber+MagicalDataImport.m │ │ ├── NSObject+MagicalDataImport.h │ │ ├── NSObject+MagicalDataImport.m │ │ ├── NSRelationshipDescription+MagicalDataImport.h │ │ ├── NSRelationshipDescription+MagicalDataImport.m │ │ ├── NSString+MagicalDataImport.h │ │ └── NSString+MagicalDataImport.m │ ├── NSManagedObject │ │ ├── NSManagedObject+MagicalAggregation.h │ │ ├── NSManagedObject+MagicalAggregation.m │ │ ├── NSManagedObject+MagicalDataImport.h │ │ ├── NSManagedObject+MagicalDataImport.m │ │ ├── NSManagedObject+MagicalFinders.h │ │ ├── NSManagedObject+MagicalFinders.m │ │ ├── NSManagedObject+MagicalRecord.h │ │ ├── NSManagedObject+MagicalRecord.m │ │ ├── NSManagedObject+MagicalRequests.h │ │ └── NSManagedObject+MagicalRequests.m │ ├── NSManagedObjectContext │ │ ├── NSManagedObjectContext+MagicalChainSave.h │ │ ├── NSManagedObjectContext+MagicalChainSave.m │ │ ├── NSManagedObjectContext+MagicalObserving.h │ │ ├── NSManagedObjectContext+MagicalObserving.m │ │ ├── NSManagedObjectContext+MagicalRecord.h │ │ ├── NSManagedObjectContext+MagicalRecord.m │ │ ├── NSManagedObjectContext+MagicalSaves.h │ │ ├── NSManagedObjectContext+MagicalSaves.m │ │ ├── NSManagedObjectContext+MagicalThreading.h │ │ └── NSManagedObjectContext+MagicalThreading.m │ ├── NSManagedObjectModel+MagicalRecord.h │ ├── NSManagedObjectModel+MagicalRecord.m │ ├── NSPersistentStore+MagicalRecord.h │ ├── NSPersistentStore+MagicalRecord.m │ ├── NSPersistentStoreCoordinator+MagicalRecord.h │ └── NSPersistentStoreCoordinator+MagicalRecord.m ├── Core │ ├── MagicalRecord+Actions.h │ ├── MagicalRecord+Actions.m │ ├── MagicalRecord+ErrorHandling.h │ ├── MagicalRecord+ErrorHandling.m │ ├── MagicalRecord+Options.h │ ├── MagicalRecord+Options.m │ ├── MagicalRecord+Setup.h │ ├── MagicalRecord+Setup.m │ ├── MagicalRecord+ShorthandMethods.h │ ├── MagicalRecord+ShorthandMethods.m │ ├── MagicalRecord+iCloud.h │ ├── MagicalRecord+iCloud.m │ ├── MagicalRecordDeprecationMacros.h │ ├── MagicalRecordInternal.h │ ├── MagicalRecordInternal.m │ ├── MagicalRecordLogging.h │ ├── MagicalRecordShorthandMethodAliases.h │ └── MagicalRecordXcode7CompatibilityMacros.h └── MagicalRecord.h ├── README.md ├── Samples └── iOS │ ├── Application │ ├── Categories │ │ ├── ImageToDataTransformer.h │ │ └── ImageToDataTransformer.m │ ├── Controllers │ │ ├── AddressBook_Prefix.pch │ │ ├── EditingTableViewCell.h │ │ ├── EditingTableViewCell.m │ │ ├── ImperialPickerController.h │ │ ├── ImperialPickerController.m │ │ ├── IngredientDetailViewController.h │ │ ├── IngredientDetailViewController.m │ │ ├── InstructionsViewController.h │ │ ├── InstructionsViewController.m │ │ ├── MetricPickerController.h │ │ ├── MetricPickerController.m │ │ ├── RecipeAddViewController.h │ │ ├── RecipeAddViewController.m │ │ ├── RecipeDetailViewController.h │ │ ├── RecipeDetailViewController.m │ │ ├── RecipeListTableViewController.h │ │ ├── RecipeListTableViewController.m │ │ ├── RecipePhotoViewController.h │ │ ├── RecipePhotoViewController.m │ │ ├── RecipeTableViewCell.h │ │ ├── RecipeTableViewCell.m │ │ ├── TemperatureCell.h │ │ ├── TemperatureCell.m │ │ ├── TemperatureConverterViewController.h │ │ ├── TemperatureConverterViewController.m │ │ ├── TypeSelectionViewController.h │ │ ├── TypeSelectionViewController.m │ │ ├── UnitConverterTableViewController.h │ │ ├── UnitConverterTableViewController.m │ │ ├── WeightConverterViewController.h │ │ └── WeightConverterViewController.m │ ├── Delegate │ │ ├── MGPRecipesAppDelegate.h │ │ └── MGPRecipesAppDelegate.m │ ├── Models │ │ ├── Recipes.xcdatamodeld │ │ │ ├── .xccurrentversion │ │ │ ├── Recipes 2.xcdatamodel │ │ │ │ ├── elements │ │ │ │ └── layout │ │ │ └── Recipes.xcdatamodel │ │ │ │ ├── elements │ │ │ │ └── layout │ │ ├── entities │ │ │ ├── Ingredient.h │ │ │ ├── Ingredient.m │ │ │ ├── Recipe.h │ │ │ └── Recipe.m │ │ └── generated │ │ │ ├── _Ingredient.h │ │ │ ├── _Ingredient.m │ │ │ ├── _Recipe.h │ │ │ └── _Recipe.m │ ├── Support │ │ ├── Recipes-Info.plist │ │ ├── Recipes-Prefix.pch │ │ ├── en.lproj │ │ │ └── InfoPlist.strings │ │ └── main.m │ └── Views │ │ ├── DetailHeaderView.xib │ │ ├── EditingTableViewCell.xib │ │ ├── InstructionsView.xib │ │ ├── MainWindow.xib │ │ ├── RecipeAddView.xib │ │ ├── TemperatureCell.xib │ │ ├── TemperatureConverter.xib │ │ └── WeightConverter.xib │ ├── MagicalRecordRecipes.xcodeproj │ └── project.pbxproj │ └── Resources │ ├── Default-568h@2x.png │ ├── Default.png │ ├── Default@2x.png │ ├── RecipeData │ ├── Recipes.sqlite │ └── TemperatureData.plist │ └── images │ ├── Icon-72.png │ ├── Icon-Small-50.png │ ├── Icon-Small.png │ ├── Icon-Small@2x.png │ ├── Icon.png │ ├── Icon@2x.png │ ├── choosePhoto.png │ ├── convert.png │ ├── fork.png │ └── iTunesArtwork ├── Support ├── Info.plist └── Scripts │ ├── GenerateShorthandAliases.rb │ ├── push_podspec.sh │ └── set_version_information.sh └── Tests ├── Core ├── MagicalRecord+ActionsTests.m ├── MagicalRecord+ShorthandTests.m ├── MagicalRecord+StackTests.m ├── MagicalRecordTestBase.h ├── MagicalRecordTestBase.m ├── NSManagedObject+MagicalRecordTests.m ├── NSManagedObject+MagicalRequestTests.m ├── NSManagedObjectContext+ChainSaveTests.m ├── NSManagedObjectContext+MagicalSavesTests.m ├── NSManagedObjectContextHelperTests.m ├── NSManagedObjectHelperTests.m ├── NSPersistentStoreCoordinatorHelperTests.m └── NSPersistentStoreHelperTests.m ├── DataImport ├── ImportMultipleEntitiesWithNoPrimaryKeyTests.m ├── ImportSingleEntityRelatedToManyMappedEntitiesUsingMappedPrimaryKeyTests.m ├── ImportSingleEntityRelatedToMappedEntityUsingDefaultsTests.m ├── ImportSingleEntityRelatedToMappedEntityUsingMappedPrimaryKeyTests.m ├── ImportSingleEntityRelatedToMappedEntityWithNestedMappedAttributesTests.m ├── ImportSingleEntityRelatedToMappedEntityWithSecondaryMappingsTests.m ├── ImportSingleEntityWithNoRelationshipsTests.m ├── ImportSingleRelatedEntityTests.m ├── MagicalDataImportTestCase.h └── MagicalDataImportTestCase.m ├── Fixtures ├── FixtureHelpers.h ├── FixtureHelpers.m ├── ImportSingleEntityRelatedToManyMappedEntitiesUsingListOfPrimaryKeysTests.m ├── MultipleEntitiesWithNoPrimaryKey.json ├── SampleJSONDataForImport.json ├── SingleEntityRelatedToManyMappedEntitiesUsingListOfPrimaryKeys.json ├── SingleEntityRelatedToManyMappedEntitiesUsingMappedPrimaryKey.json ├── SingleEntityRelatedToMappedEntityUsingDefaults.json ├── SingleEntityRelatedToMappedEntityUsingMappedPrimaryKey.json ├── SingleEntityRelatedToMappedEntityWithNestedMappedAttributes.json ├── SingleEntityRelatedToMappedEntityWithSecondaryMappings.json ├── SingleEntityWithNoRelationships.json ├── SingleEntityWithNoRelationships.plist ├── SingleRelatedEntity.json ├── TestModel.xcdatamodeld │ └── TestModel.xcdatamodel │ │ └── contents └── TestModel │ ├── AbstractRelatedEntity.h │ ├── AbstractRelatedEntity.m │ ├── ConcreteRelatedEntity.h │ ├── ConcreteRelatedEntity.m │ ├── DifferentClassNameMapping.h │ ├── DifferentClassNameMapping.m │ ├── EntityWithoutEntityNameMethod.h │ ├── EntityWithoutEntityNameMethod.m │ ├── MappedEntity.h │ ├── MappedEntity.m │ ├── SingleEntityRelatedToManyMappedEntitiesUsingMappedPrimaryKey.h │ ├── SingleEntityRelatedToManyMappedEntitiesUsingMappedPrimaryKey.m │ ├── SingleEntityRelatedToMappedEntityUsingDefaults.h │ ├── SingleEntityRelatedToMappedEntityUsingDefaults.m │ ├── SingleEntityRelatedToMappedEntityUsingMappedPrimaryKey.h │ ├── SingleEntityRelatedToMappedEntityUsingMappedPrimaryKey.m │ ├── SingleEntityRelatedToMappedEntityWithNestedMappedAttributes.h │ ├── SingleEntityRelatedToMappedEntityWithNestedMappedAttributes.m │ ├── SingleEntityRelatedToMappedEntityWithSecondaryMappings.h │ ├── SingleEntityRelatedToMappedEntityWithSecondaryMappings.m │ ├── SingleEntityWithNoRelationships.h │ ├── SingleEntityWithNoRelationships.m │ ├── SingleRelatedEntity.h │ ├── SingleRelatedEntity.m │ ├── _AbstractRelatedEntity.h │ ├── _AbstractRelatedEntity.m │ ├── _ConcreteRelatedEntity.h │ ├── _ConcreteRelatedEntity.m │ ├── _DifferentClassNameMapping.h │ ├── _DifferentClassNameMapping.m │ ├── _MappedEntity.h │ ├── _MappedEntity.m │ ├── _SingleEntityRelatedToManyMappedEntitiesUsingMappedPrimaryKey.h │ ├── _SingleEntityRelatedToManyMappedEntitiesUsingMappedPrimaryKey.m │ ├── _SingleEntityRelatedToMappedEntityUsingDefaults.h │ ├── _SingleEntityRelatedToMappedEntityUsingDefaults.m │ ├── _SingleEntityRelatedToMappedEntityUsingMappedPrimaryKey.h │ ├── _SingleEntityRelatedToMappedEntityUsingMappedPrimaryKey.m │ ├── _SingleEntityRelatedToMappedEntityWithNestedMappedAttributes.h │ ├── _SingleEntityRelatedToMappedEntityWithNestedMappedAttributes.m │ ├── _SingleEntityRelatedToMappedEntityWithSecondaryMappings.h │ ├── _SingleEntityRelatedToMappedEntityWithSecondaryMappings.m │ ├── _SingleEntityWithNoRelationships.h │ ├── _SingleEntityWithNoRelationships.m │ ├── _SingleRelatedEntity.h │ └── _SingleRelatedEntity.m └── Support ├── MagicalRecordTestHelpers.h ├── MagicalRecordTestHelpers.m ├── MagicalRecordTests-OSX-Info.plist ├── MagicalRecordTests-OSX-Prefix.pch ├── MagicalRecordTests-iOS-Info.plist ├── MagicalRecordTests-iOS-Prefix.pch └── MagicalRecordTests-tvOS-Info.plist /.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: Chromium 2 | AlignTrailingComments: true 3 | BraceWrapping: 4 | AfterClass: true 5 | AfterControlStatement: true 6 | AfterEnum: true 7 | AfterFunction: true 8 | AfterNamespace: true 9 | AfterObjCDeclaration: true 10 | AfterStruct: true 11 | AfterUnion: false 12 | BeforeCatch: true 13 | BeforeElse: true 14 | IndentBraces: false 15 | BreakBeforeBraces: Allman 16 | ColumnLimit: 0 17 | IndentCaseLabels: true 18 | IndentWidth: 4 19 | KeepEmptyLinesAtTheStartOfBlocks: false 20 | MaxEmptyLinesToKeep: 1 21 | NamespaceIndentation: None 22 | ObjCBlockIndentWidth: 4 23 | ObjCSpaceAfterProperty: true 24 | ObjCSpaceBeforeProtocolList: true 25 | PointerAlignment: Right 26 | SpaceAfterCStyleCast: false 27 | SpaceBeforeAssignmentOperators: true 28 | SpaceBeforeParens: ControlStatements 29 | SpaceInEmptyParentheses: false 30 | SpacesBeforeTrailingComments: 1 31 | SpacesInAngles: false 32 | SpacesInContainerLiterals: true 33 | SpacesInCStyleCastParentheses: false 34 | SpacesInParentheses: false 35 | SpacesInSquareBrackets: false 36 | Standard: Auto 37 | TabWidth: 4 38 | UseTab: Never 39 | -------------------------------------------------------------------------------- /.cocoadocs.yml: -------------------------------------------------------------------------------- 1 | additional_guides: 2 | - https://github.com/magicalpanda/MagicalRecord/wiki/Installing-MagicalRecord 3 | - https://github.com/magicalpanda/MagicalRecord/wiki/Getting-Started 4 | - https://github.com/magicalpanda/MagicalRecord/wiki/Working-with-Managed-Object-Contexts 5 | - https://github.com/magicalpanda/MagicalRecord/wiki/Creating-Entities 6 | - https://github.com/magicalpanda/MagicalRecord/wiki/Deleting-Entities 7 | - https://github.com/magicalpanda/MagicalRecord/wiki/Fetching-Entities 8 | - https://github.com/magicalpanda/MagicalRecord/wiki/Saving 9 | - https://github.com/magicalpanda/MagicalRecord/wiki/Usage-Patterns 10 | - https://github.com/magicalpanda/MagicalRecord/wiki/Importing-Data 11 | - https://github.com/magicalpanda/MagicalRecord/wiki/Logging 12 | - https://github.com/magicalpanda/MagicalRecord/wiki/Upgrading-to-MagicalRecord-2.3 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Finder 2 | .DS_Store 3 | 4 | # Xcode 5 | build/* 6 | *.pbxuser 7 | !default.pbxuser 8 | *.mode1v3 9 | !default.mode1v3 10 | *.mode2v3 11 | !default.mode2v3 12 | *.perspectivev3 13 | !default.perspectivev3 14 | *.xcworkspace 15 | !default.xcworkspace 16 | xcuserdata 17 | profile 18 | *.moved-aside 19 | 20 | DerivedData 21 | Carthage/Build 22 | 23 | *.gcno 24 | *.gcda 25 | 26 | MagicalRecord.framework.zip 27 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Thanks for contributing to this project! 2 | 3 | To make the process as easy as possible, we've got a few guidelines that we'd appreciate you following: 4 | 5 | ## Filing Issues 6 | 7 | Before you file an issue, please ensure that: 8 | 9 | 1. **It's a bug or a feature request** — if you're looking for help using MagicalRecord, please ask your question on [Stack Overflow](https://stackoverflow.com/). We monitor the [**MagicalRecord** tag](https://stackoverflow.com/questions/tagged/magicalrecord) so be sure to tag your question so that we see it 10 | 1. **Search for an existing issue** — there's a good chance you're not the only one experiencing the problem you've come to tell us about 11 | 2. **Include as much information as you can** — if we can't reproduce the problem you've filed, we can't fix it. Include crash logs, exception reports and code if you can. 12 | 13 | ## We Prefer Pull Requests 14 | 15 | If you know exactly how to implement the feature being suggested or fix the bug being reported, please open a pull request instead of an issue. Pull requests are easier than patches or inline code blocks for discussing and merging the changes. Please ensure that you include tests in the Pull Request — we use XCTest. 16 | 17 | If you can't make the change yourself, please open an issue after making sure that one isn't already logged. 18 | 19 | ## Contributing Code 20 | 21 | Fork this repository, make some great changes (preferably in a branch named for the topic of the changes you're making) and send a pull request! 22 | 23 | All code contributions should match our [coding conventions](https://github.com/magicalpanda/MagicalRecord/wiki/Coding-Conventions). 24 | 25 | Thanks for reading the guidelines! 26 | -------------------------------------------------------------------------------- /Docs/Creating-Entities.md: -------------------------------------------------------------------------------- 1 | # Creating Entities 2 | 3 | To create and insert a new instance of an Entity in the default context, you can use: 4 | 5 | ```objective-c 6 | // Objective-C 7 | Person *myPerson = [Person MR_createEntity]; 8 | ``` 9 | 10 | ```swift 11 | // Swift 12 | let myPerson = Person.mr_createEntity() 13 | ``` 14 | 15 | 16 | To create and insert an entity into specific context: 17 | 18 | ```objective-c 19 | // Objective-C 20 | Person *myPerson = [Person MR_createEntityInContext:otherContext]; 21 | ``` 22 | 23 | ```swift 24 | // Swift 25 | let myPerson = Person.mr_createEntity(in: otherContext) 26 | ``` 27 | -------------------------------------------------------------------------------- /Docs/Deleting-Entities.md: -------------------------------------------------------------------------------- 1 | # Deleting Entities 2 | 3 | To delete a single entity in the default context: 4 | 5 | ```objective-c 6 | // Objective-C 7 | [myPerson MR_deleteEntity]; 8 | ``` 9 | 10 | ```swift 11 | // Swift 12 | myPerson.mr_deleteEntity() 13 | ``` 14 | 15 | 16 | To delete the entity from a specific context: 17 | 18 | ```objective-c 19 | // Objective-C 20 | [myPerson MR_deleteEntityInContext:otherContext]; 21 | ``` 22 | 23 | ```swift 24 | // Swift 25 | myPerson.mr_deleteEntity(in: otherContext) 26 | ``` 27 | 28 | 29 | To truncate all entities from the default context: 30 | 31 | ```objective-c 32 | // Objective-C 33 | [Person MR_truncateAll]; 34 | ``` 35 | 36 | ```swift 37 | // Swift 38 | Person.mr_truncateAll() 39 | ``` 40 | 41 | To truncate all entities in a specific context: 42 | 43 | ```objective-c 44 | // Objective-C 45 | [Person MR_truncateAllInContext:otherContext]; 46 | ``` 47 | 48 | ```swift 49 | // Swift 50 | Person.mr_truncateAll(in: otherContext) 51 | ``` 52 | -------------------------------------------------------------------------------- /Docs/Logging.md: -------------------------------------------------------------------------------- 1 | ## Logging 2 | 3 | MagicalRecord has logging built in to most of its interactions with Core Data. When errors occur during fetching or saving data, these errors are captured and (if you've enabled them) logged to the console. 4 | 5 | Logging is configured to output debugging messages (**MagicalRecordLoggingLevelDebug**) by default in debug builds, and will output error messages (**MagicalRecordLoggingLevelError**) in release builds. 6 | 7 | Logging can be configured by calling `[MagicalRecord setLoggingLevel:];` using one of the predefined logging levels: 8 | 9 | - **MagicalRecordLogLevelOff**: Don't log anything 10 | - **MagicalRecordLoggingLevelError**: Log all errors 11 | - **MagicalRecordLoggingLevelWarn**: Log warnings and errors 12 | - **MagicalRecordLoggingLevelInfo**: Log informative, warning and error messages 13 | - **MagicalRecordLoggingLevelDebug**: Log all debug, informative, warning and error messages 14 | - **MagicalRecordLoggingLevelVerbose**: Log verbose diagnostic, informative, warning and error messages 15 | 16 | The logging level defaults to `MagicalRecordLoggingLevelWarn`. 17 | 18 | ## CocoaLumberjack 19 | 20 | If it's available, MagicalRecord will direct its logs to [CocoaLumberjack](https://github.com/CocoaLumberjack/CocoaLumberjack). All you need to do is make sure you've imported CocoaLumberjack before you import MagicalRecord, like so: 21 | 22 | ```objective-c 23 | // Objective-C 24 | #import 25 | #import 26 | ``` 27 | 28 | ```swift 29 | // Swift 30 | import CocoaLumberjack 31 | import MagicalRecord 32 | ``` 33 | 34 | ## Disabling Logging Completely 35 | 36 | For most people this should be unnecessary. Setting the logging level to **MagicalRecordLogLevelOff** will ensure that no logs are printed. 37 | 38 | Even when using `MagicalRecordLogLevelOff`, a very quick check may be performed whenever a log call is made. If you absolutely need to disable the logging, you will need to define the following when compiling MagicalRecord: 39 | 40 | ```objective-c 41 | #define MR_LOGGING_DISABLED 1 42 | ``` 43 | 44 | Please note that this will only work if you've added MagicalRecord's source to your own project. You can also add this to the MagicalRecord project's `OTHER_CFLAGS` as `-DMR_LOGGING_DISABLED=1`. 45 | -------------------------------------------------------------------------------- /Docs/Other-Resources.md: -------------------------------------------------------------------------------- 1 | # Resources 2 | 3 | The following articles highlight how to install and use aspects of MagicalRecord: 4 | 5 | * [How to make Programming with Core Data Pleasant](http://yannickloriot.com/2012/03/magicalrecord-how-to-make-programming-with-core-data-pleasant/) 6 | * [Using Core Data with MagicalRecord](https://web.archive.org/web/20120702085039/http://ablfx.com/blog/2012/03/using-coredata-magicalrecord/) 7 | * [Super Happy Easy Fetching in Core Data](http://www.cimgf.com/2011/03/13/super-happy-easy-fetching-in-core-data/) 8 | * [Core Data and Threads, without the Headache](http://www.cimgf.com/2011/05/04/core-data-and-threads-without-the-headache/) 9 | * [Unit Testing with Core Data](http://www.cimgf.com/2012/05/15/unit-testing-with-core-data/) 10 | * [Using MagicalRecord with Swift](https://www.raywenderlich.com/1696-getting-started-with-magicalrecord) 11 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010-2015, Magical Panda Software, LLC 2 | 3 | Permission is hereby granted, free of charge, to any person 4 | obtaining a copy of this software and associated documentation 5 | files (the "Software"), to deal in the Software without 6 | restriction, including without limitation the rights to use, 7 | copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the 9 | Software is furnished to do so, subject to the following 10 | conditions: 11 | 12 | * Link to the MagicalRecord Repository at https://github.com/magicalpanda/MagicalRecord in the credits section of your application 13 | 14 | The above copyright notice and this permission notice shall be 15 | included in all copies or substantial portions of the Software. 16 | 17 | This software license is in accordance with the standard MIT License. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 21 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 23 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 24 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 26 | OTHER DEALINGS IN THE SOFTWARE. 27 | -------------------------------------------------------------------------------- /MagicalRecord.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.default_subspec = 'Core' 3 | s.name = 'MagicalRecord' 4 | s.version = '2.4.0' 5 | s.license = 'MIT' 6 | s.summary = 'Super Awesome Easy Fetching for Core Data!' 7 | s.homepage = 'https://github.com/magicalpanda/MagicalRecord' 8 | s.author = { 'Saul Mora' => 'saul@magicalpanda.com', 'Tony Arnold' => 'tony@thecocoabots.com' } 9 | s.source = { :git => 'https://github.com/magicalpanda/MagicalRecord.git', :tag => "v#{s.version}" } 10 | s.description = 'Handy fetching, threading and data import helpers to make Core Data a little easier to use.' 11 | s.ios.deployment_target = '8.0' 12 | s.osx.deployment_target = '10.8' 13 | s.tvos.deployment_target = '9.0' 14 | s.watchos.deployment_target = '2.0' 15 | 16 | s.subspec 'Core' do |sp| 17 | sp.framework = 'CoreData' 18 | sp.header_dir = 'MagicalRecord' 19 | sp.source_files = 'MagicalRecord/**/*.{h,m}' 20 | sp.exclude_files = '**/MagicalRecordShorthandMethodAliases.h' 21 | sp.prefix_header_contents = <<-EOS 22 | #import 23 | #import 24 | EOS 25 | end 26 | 27 | s.subspec 'ShorthandMethodAliases' do |sp| 28 | sp.source_files = '**/MagicalRecordShorthandMethodAliases.h' 29 | end 30 | 31 | s.subspec 'CocoaLumberjack' do |sp| 32 | sp.dependency 'CocoaLumberjack', '~> 3.0' 33 | sp.dependency 'MagicalRecord/Core' 34 | end 35 | 36 | end 37 | -------------------------------------------------------------------------------- /MagicalRecord.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /MagicalRecord/Categories/DataImport/MagicalImportFunctions.h: -------------------------------------------------------------------------------- 1 | // 2 | // MagicalImportFunctions.h 3 | // Magical Record 4 | // 5 | // Created by Saul Mora on 3/7/12. 6 | // Copyright (c) 2012 Magical Panda Software LLC. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | NSDate * __MR_nonnull MR_adjustDateForDST(NSDate *__MR_nonnull date); 13 | NSDate * __MR_nonnull MR_dateFromString(NSString *__MR_nonnull value, NSString *__MR_nonnull format); 14 | NSDate * __MR_nonnull MR_dateFromNumber(NSNumber *__MR_nonnull value, BOOL milliseconds); 15 | NSNumber * __MR_nonnull MR_numberFromString(NSString *__MR_nonnull value); 16 | NSString * __MR_nonnull MR_attributeNameFromString(NSString *__MR_nonnull value); 17 | NSString * __MR_nonnull MR_primaryKeyNameFromString(NSString *__MR_nonnull value); 18 | 19 | #if TARGET_OS_IPHONE 20 | #import 21 | UIColor * __MR_nullable MR_colorFromString(NSString *__MR_nonnull serializedColor); 22 | #else 23 | #import 24 | NSColor * __MR_nullable MR_colorFromString(NSString *__MR_nonnull serializedColor); 25 | #endif 26 | 27 | NSInteger * __MR_nullable MR_newColorComponentsFromString(NSString *__MR_nonnull serializedColor); 28 | -------------------------------------------------------------------------------- /MagicalRecord/Categories/DataImport/NSAttributeDescription+MagicalDataImport.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSAttributeDescription+MagicalDataImport.h 3 | // Magical Record 4 | // 5 | // Created by Saul Mora on 9/4/11. 6 | // Copyright 2011 Magical Panda Software LLC. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface NSAttributeDescription (MagicalRecord_DataImport) 13 | 14 | - (MR_nullable NSString *) MR_primaryKey; 15 | - (MR_nullable id) MR_valueForKeyPath:(MR_nonnull NSString *)keyPath fromObjectData:(MR_nonnull id)objectData; 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /MagicalRecord/Categories/DataImport/NSAttributeDescription+MagicalDataImport.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSAttributeDescription+MagicalDataImport.m 3 | // Magical Record 4 | // 5 | // Created by Saul Mora on 9/4/11. 6 | // Copyright 2011 Magical Panda Software LLC. All rights reserved. 7 | // 8 | 9 | #import "NSAttributeDescription+MagicalDataImport.h" 10 | #import "NSManagedObject+MagicalDataImport.h" 11 | #import "MagicalImportFunctions.h" 12 | 13 | @implementation NSAttributeDescription (MagicalRecord_DataImport) 14 | 15 | - (NSString *) MR_primaryKey 16 | { 17 | return nil; 18 | } 19 | 20 | - (id) MR_valueForKeyPath:(NSString *)keyPath fromObjectData:(id)objectData 21 | { 22 | id value = [objectData valueForKeyPath:keyPath]; 23 | 24 | NSAttributeType attributeType = [self attributeType]; 25 | NSString *desiredAttributeType = [[self userInfo] objectForKey:kMagicalRecordImportAttributeValueClassNameKey]; 26 | if (desiredAttributeType) 27 | { 28 | if ([desiredAttributeType hasSuffix:@"Color"]) 29 | { 30 | value = MR_colorFromString(value); 31 | } 32 | } 33 | else 34 | { 35 | if (attributeType == NSDateAttributeType) 36 | { 37 | if (![value isKindOfClass:[NSDate class]]) 38 | { 39 | NSString *dateFormat = [[self userInfo] objectForKey:kMagicalRecordImportCustomDateFormatKey]; 40 | if ([value isKindOfClass:[NSNumber class]]) { 41 | value = MR_dateFromNumber(value, [dateFormat isEqualToString:kMagicalRecordImportUnixTimeString]); 42 | } 43 | else { 44 | value = MR_dateFromString([value description], dateFormat ?: kMagicalRecordImportDefaultDateFormatString); 45 | } 46 | } 47 | } 48 | else if (attributeType == NSInteger16AttributeType || 49 | attributeType == NSInteger32AttributeType || 50 | attributeType == NSInteger64AttributeType || 51 | attributeType == NSDecimalAttributeType || 52 | attributeType == NSDoubleAttributeType || 53 | attributeType == NSFloatAttributeType) { 54 | if (![value isKindOfClass:[NSNumber class]] && value != [NSNull null]) { 55 | value = MR_numberFromString([value description]); 56 | } 57 | } 58 | else if (attributeType == NSBooleanAttributeType) { 59 | if (![value isKindOfClass:[NSNumber class]] && value != [NSNull null]) { 60 | value = [NSNumber numberWithBool:[value boolValue]]; 61 | } 62 | } 63 | else if (attributeType == NSStringAttributeType) { 64 | if (![value isKindOfClass:[NSString class]] && value != [NSNull null]) { 65 | value = [value description]; 66 | } 67 | } 68 | } 69 | 70 | return value == [NSNull null] ? nil : value; 71 | } 72 | 73 | @end 74 | -------------------------------------------------------------------------------- /MagicalRecord/Categories/DataImport/NSEntityDescription+MagicalDataImport.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSEntityDescription+MagicalDataImport.h 3 | // Magical Record 4 | // 5 | // Created by Saul Mora on 9/5/11. 6 | // Copyright 2011 Magical Panda Software LLC. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface NSEntityDescription (MagicalRecord_DataImport) 13 | 14 | - (MR_nullable NSAttributeDescription *) MR_primaryAttributeToRelateBy; 15 | - (MR_nonnull NSManagedObject *) MR_createInstanceInContext:(MR_nonnull NSManagedObjectContext *)context; 16 | 17 | /** 18 | * Safely returns an attribute description for the given name, otherwise returns nil. In certain circumstances, the keys of the dictionary returned by `attributesByName` are not standard NSStrings and won't match using object subscripting or standard `objectForKey:` lookups. 19 | * 20 | * There may be performance implications to using this method if your entity has hundreds or thousands of attributes. 21 | * 22 | * @param name Name of the attribute description in the `attributesByName` dictionary on this instance 23 | * 24 | * @return The attribute description for the given name, otherwise nil 25 | */ 26 | - (MR_nullable NSAttributeDescription *) MR_attributeDescriptionForName:(MR_nonnull NSString *)name; 27 | 28 | @end 29 | -------------------------------------------------------------------------------- /MagicalRecord/Categories/DataImport/NSEntityDescription+MagicalDataImport.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSEntityDescription+MagicalDataImport.m 3 | // Magical Record 4 | // 5 | // Created by Saul Mora on 9/5/11. 6 | // Copyright 2011 Magical Panda Software LLC. All rights reserved. 7 | // 8 | 9 | #import "NSEntityDescription+MagicalDataImport.h" 10 | #import "NSManagedObject+MagicalDataImport.h" 11 | #import "NSManagedObject+MagicalRecord.h" 12 | #import "MagicalImportFunctions.h" 13 | #import "MagicalRecordLogging.h" 14 | 15 | @implementation NSEntityDescription (MagicalRecord_DataImport) 16 | 17 | - (NSAttributeDescription *) MR_primaryAttributeToRelateBy 18 | { 19 | NSString *lookupKey = [[self userInfo] objectForKey:kMagicalRecordImportRelationshipLinkedByKey] ?: MR_primaryKeyNameFromString([self name]); 20 | NSAttributeDescription *attributeDescription = [self MR_attributeDescriptionForName:lookupKey]; 21 | 22 | if (attributeDescription == nil) 23 | { 24 | MRLogError( 25 | @"Invalid value for key '%@' in '%@' entity. Remove this key or add attribute '%@'\n", 26 | kMagicalRecordImportRelationshipLinkedByKey, 27 | self.name, 28 | lookupKey); 29 | } 30 | 31 | return attributeDescription; 32 | } 33 | 34 | - (NSManagedObject *) MR_createInstanceInContext:(NSManagedObjectContext *)context 35 | { 36 | Class relatedClass = NSClassFromString([self managedObjectClassName]); 37 | NSManagedObject *newInstance = [relatedClass MR_createEntityInContext:context]; 38 | 39 | return newInstance; 40 | } 41 | 42 | - (NSAttributeDescription *) MR_attributeDescriptionForName:(NSString *)name 43 | { 44 | __block NSAttributeDescription *attributeDescription; 45 | 46 | NSDictionary *attributesByName = [self attributesByName]; 47 | 48 | if ([attributesByName count] == 0) { 49 | return nil; 50 | } 51 | 52 | [attributesByName enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { 53 | if ([key isEqualToString:name]) { 54 | attributeDescription = obj; 55 | 56 | *stop = YES; 57 | } 58 | }]; 59 | 60 | return attributeDescription; 61 | } 62 | 63 | @end 64 | -------------------------------------------------------------------------------- /MagicalRecord/Categories/DataImport/NSNumber+MagicalDataImport.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSNumber+MagicalDataImport.h 3 | // Magical Record 4 | // 5 | // Created by Saul Mora on 9/4/11. 6 | // Copyright 2011 Magical Panda Software LLC. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | #import 12 | 13 | @interface NSNumber (MagicalRecord_DataImport) 14 | 15 | - (MR_nullable NSString *)MR_lookupKeyForAttribute:(MR_nonnull NSAttributeDescription *)attributeInfo; 16 | - (MR_nonnull id)MR_relatedValueForRelationship:(MR_nonnull NSRelationshipDescription *)relationshipInfo; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /MagicalRecord/Categories/DataImport/NSNumber+MagicalDataImport.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSNumber+MagicalDataImport.m 3 | // Magical Record 4 | // 5 | // Created by Saul Mora on 9/4/11. 6 | // Copyright 2011 Magical Panda Software LLC. All rights reserved. 7 | // 8 | 9 | #import "NSNumber+MagicalDataImport.h" 10 | 11 | @implementation NSNumber (MagicalRecord_DataImport) 12 | 13 | - (NSString *)MR_lookupKeyForAttribute:(NSAttributeDescription *)attributeInfo 14 | { 15 | return nil; 16 | } 17 | 18 | - (id)MR_relatedValueForRelationship:(NSRelationshipDescription *)relationshipInfo 19 | { 20 | return self; 21 | } 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /MagicalRecord/Categories/DataImport/NSObject+MagicalDataImport.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSDictionary+MagicalDataImport.h 3 | // Magical Record 4 | // 5 | // Created by Saul Mora on 9/4/11. 6 | // Copyright 2011 Magical Panda Software LLC. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | #import 12 | 13 | @interface NSObject (MagicalRecord_DataImport) 14 | 15 | - (MR_nullable NSString *) MR_lookupKeyForAttribute:(MR_nonnull NSAttributeDescription *)attributeInfo; 16 | - (MR_nullable id) MR_valueForAttribute:(MR_nonnull NSAttributeDescription *)attributeInfo; 17 | 18 | - (MR_nullable NSString *) MR_lookupKeyForRelationship:(MR_nonnull NSRelationshipDescription *)relationshipInfo; 19 | - (MR_nullable id) MR_relatedValueForRelationship:(MR_nonnull NSRelationshipDescription *)relationshipInfo; 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /MagicalRecord/Categories/DataImport/NSObject+MagicalDataImport.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSDictionary+MagicalDataImport.m 3 | // Magical Record 4 | // 5 | // Created by Saul Mora on 9/4/11. 6 | // Copyright 2011 Magical Panda Software LLC. All rights reserved. 7 | // 8 | 9 | #import "NSObject+MagicalDataImport.h" 10 | #import "NSAttributeDescription+MagicalDataImport.h" 11 | #import "NSEntityDescription+MagicalDataImport.h" 12 | #import "NSManagedObject+MagicalDataImport.h" 13 | #import "NSRelationshipDescription+MagicalDataImport.h" 14 | #import "MagicalRecordLogging.h" 15 | 16 | NSUInteger const kMagicalRecordImportMaximumAttributeFailoverDepth = 10; 17 | 18 | 19 | @implementation NSObject (MagicalRecord_DataImport) 20 | 21 | - (NSString *) MR_lookupKeyForAttribute:(NSAttributeDescription *)attributeInfo 22 | { 23 | NSString *attributeName = [attributeInfo name]; 24 | NSString *lookupKey = [[attributeInfo userInfo] objectForKey:kMagicalRecordImportAttributeKeyMapKey] ?: attributeName; 25 | 26 | id value = [self valueForKeyPath:lookupKey]; 27 | 28 | for (NSUInteger i = 1; i < kMagicalRecordImportMaximumAttributeFailoverDepth && value == nil; i++) 29 | { 30 | attributeName = [NSString stringWithFormat:@"%@.%lu", kMagicalRecordImportAttributeKeyMapKey, (unsigned long)i]; 31 | lookupKey = [[attributeInfo userInfo] objectForKey:attributeName]; 32 | if (lookupKey == nil) 33 | { 34 | return nil; 35 | } 36 | value = [self valueForKeyPath:lookupKey]; 37 | } 38 | 39 | return value != nil ? lookupKey : nil; 40 | } 41 | 42 | - (id) MR_valueForAttribute:(NSAttributeDescription *)attributeInfo 43 | { 44 | NSString *lookupKey = [self MR_lookupKeyForAttribute:attributeInfo]; 45 | return lookupKey ? [self valueForKeyPath:lookupKey] : nil; 46 | } 47 | 48 | - (NSString *) MR_lookupKeyForRelationship:(NSRelationshipDescription *)relationshipInfo 49 | { 50 | NSEntityDescription *destinationEntity = [relationshipInfo destinationEntity]; 51 | if (destinationEntity == nil) 52 | { 53 | MRLogError(@"Unable to find entity for type '%@'", [self valueForKey:kMagicalRecordImportRelationshipTypeKey]); 54 | return nil; 55 | } 56 | 57 | NSString *primaryKeyName = [relationshipInfo MR_primaryKey]; 58 | NSAttributeDescription *primaryKeyAttribute = [destinationEntity MR_attributeDescriptionForName:primaryKeyName]; 59 | NSString *lookupKey = [self MR_lookupKeyForAttribute:primaryKeyAttribute] ?: [primaryKeyAttribute name]; 60 | 61 | return lookupKey; 62 | } 63 | 64 | - (id) MR_relatedValueForRelationship:(NSRelationshipDescription *)relationshipInfo 65 | { 66 | NSString *lookupKey = [self MR_lookupKeyForRelationship:relationshipInfo]; 67 | return lookupKey ? [self valueForKeyPath:lookupKey] : nil; 68 | } 69 | 70 | @end 71 | -------------------------------------------------------------------------------- /MagicalRecord/Categories/DataImport/NSRelationshipDescription+MagicalDataImport.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSRelationshipDescription+MagicalDataImport.h 3 | // Magical Record 4 | // 5 | // Created by Saul Mora on 9/4/11. 6 | // Copyright 2011 Magical Panda Software LLC. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface NSRelationshipDescription (MagicalRecord_DataImport) 13 | 14 | - (MR_nonnull NSString *) MR_primaryKey; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /MagicalRecord/Categories/DataImport/NSRelationshipDescription+MagicalDataImport.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSRelationshipDescription+MagicalDataImport.m 3 | // Magical Record 4 | // 5 | // Created by Saul Mora on 9/4/11. 6 | // Copyright 2011 Magical Panda Software LLC. All rights reserved. 7 | // 8 | 9 | #import "NSRelationshipDescription+MagicalDataImport.h" 10 | #import "NSManagedObject+MagicalDataImport.h" 11 | #import "MagicalImportFunctions.h" 12 | 13 | @implementation NSRelationshipDescription (MagicalRecord_DataImport) 14 | 15 | - (NSString *) MR_primaryKey 16 | { 17 | NSString *primaryKeyName = [[self userInfo] objectForKey:kMagicalRecordImportRelationshipLinkedByKey] ?: 18 | MR_primaryKeyNameFromString([[self destinationEntity] name]); 19 | 20 | return primaryKeyName; 21 | } 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /MagicalRecord/Categories/DataImport/NSString+MagicalDataImport.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+MagicalDataImport.h 3 | // Magical Record 4 | // 5 | // Created by Saul Mora on 12/10/11. 6 | // Copyright (c) 2011 Magical Panda Software LLC. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | #import 12 | 13 | @interface NSString (MagicalRecord_DataImport) 14 | 15 | - (MR_nonnull NSString *) MR_capitalizedFirstCharacterString; 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /MagicalRecord/Categories/DataImport/NSString+MagicalDataImport.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+MagicalDataImport.m 3 | // Magical Record 4 | // 5 | // Created by Saul Mora on 12/10/11. 6 | // Copyright (c) 2011 Magical Panda Software LLC. All rights reserved. 7 | // 8 | 9 | #import "NSString+MagicalDataImport.h" 10 | 11 | 12 | @implementation NSString (MagicalRecord_DataImport) 13 | 14 | - (NSString *) MR_capitalizedFirstCharacterString 15 | { 16 | if ([self length] > 0) 17 | { 18 | NSString *firstChar = [[self substringToIndex:1] capitalizedString]; 19 | return [firstChar stringByAppendingString:[self substringFromIndex:1]]; 20 | } 21 | return self; 22 | } 23 | 24 | - (id) MR_relatedValueForRelationship:(NSRelationshipDescription *)relationshipInfo 25 | { 26 | return self; 27 | } 28 | 29 | - (NSString *) MR_lookupKeyForAttribute:(NSAttributeDescription *)attributeInfo 30 | { 31 | return nil; 32 | } 33 | 34 | @end 35 | 36 | -------------------------------------------------------------------------------- /MagicalRecord/Categories/NSManagedObject/NSManagedObject+MagicalDataImport.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSManagedObject+MagicalDataImport.h 3 | // 4 | // Created by Saul Mora on 6/28/11. 5 | // Copyright 2011 Magical Panda Software LLC. All rights reserved. 6 | // 7 | 8 | #import 9 | #import 10 | 11 | OBJC_EXPORT NSString * __MR_nonnull const kMagicalRecordImportCustomDateFormatKey; 12 | OBJC_EXPORT NSString * __MR_nonnull const kMagicalRecordImportDefaultDateFormatString; 13 | OBJC_EXPORT NSString * __MR_nonnull const kMagicalRecordImportUnixTimeString; 14 | OBJC_EXPORT NSString * __MR_nonnull const kMagicalRecordImportAttributeKeyMapKey; 15 | OBJC_EXPORT NSString * __MR_nonnull const kMagicalRecordImportAttributeValueClassNameKey; 16 | 17 | OBJC_EXPORT NSString * __MR_nonnull const kMagicalRecordImportRelationshipMapKey; 18 | OBJC_EXPORT NSString * __MR_nonnull const kMagicalRecordImportRelationshipLinkedByKey; 19 | OBJC_EXPORT NSString * __MR_nonnull const kMagicalRecordImportRelationshipTypeKey; 20 | 21 | @protocol MagicalRecordDataImportProtocol 22 | 23 | @optional 24 | - (BOOL) shouldImport:(MR_nonnull id)data; 25 | - (void) willImport:(MR_nonnull id)data; 26 | - (void) didImport:(MR_nonnull id)data; 27 | 28 | @end 29 | 30 | @interface NSManagedObject (MagicalRecord_DataImport) 31 | 32 | - (BOOL) MR_importValuesForKeysWithObject:(MR_nonnull id)objectData; 33 | 34 | + (MR_nonnull instancetype) MR_importFromObject:(MR_nonnull id)data; 35 | + (MR_nonnull instancetype) MR_importFromObject:(MR_nonnull id)data inContext:(MR_nonnull NSManagedObjectContext *)context; 36 | 37 | + (MR_nonnull MR_NSArrayOfNSManagedObjects) MR_importFromArray:(MR_nonnull MR_GENERIC(NSArray, NSDictionary *) *)listOfObjectData; 38 | + (MR_nonnull MR_NSArrayOfNSManagedObjects) MR_importFromArray:(MR_nonnull MR_GENERIC(NSArray, NSDictionary *) *)listOfObjectData inContext:(MR_nonnull NSManagedObjectContext *)context; 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /MagicalRecord/Categories/NSManagedObject/NSManagedObject+MagicalRequests.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSManagedObject+MagicalRequests.h 3 | // Magical Record 4 | // 5 | // Created by Saul Mora on 3/7/12. 6 | // Copyright (c) 2012 Magical Panda Software LLC. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface NSManagedObject (MagicalRequests) 13 | 14 | + (MR_nonnull NSFetchRequest *) MR_createFetchRequest; 15 | + (MR_nonnull NSFetchRequest *) MR_createFetchRequestInContext:(MR_nonnull NSManagedObjectContext *)context; 16 | 17 | + (MR_nonnull NSFetchRequest *) MR_requestAll; 18 | + (MR_nonnull NSFetchRequest *) MR_requestAllInContext:(MR_nonnull NSManagedObjectContext *)context; 19 | + (MR_nonnull NSFetchRequest *) MR_requestAllWithPredicate:(MR_nullable NSPredicate *)searchTerm; 20 | + (MR_nonnull NSFetchRequest *) MR_requestAllWithPredicate:(MR_nullable NSPredicate *)searchTerm inContext:(MR_nonnull NSManagedObjectContext *)context; 21 | + (MR_nonnull NSFetchRequest *) MR_requestAllWhere:(MR_nonnull NSString *)property isEqualTo:(MR_nonnull id)value; 22 | + (MR_nonnull NSFetchRequest *) MR_requestAllWhere:(MR_nonnull NSString *)property isEqualTo:(MR_nonnull id)value inContext:(MR_nonnull NSManagedObjectContext *)context; 23 | + (MR_nonnull NSFetchRequest *) MR_requestFirstWithPredicate:(MR_nullable NSPredicate *)searchTerm; 24 | + (MR_nonnull NSFetchRequest *) MR_requestFirstWithPredicate:(MR_nullable NSPredicate *)searchTerm inContext:(MR_nonnull NSManagedObjectContext *)context; 25 | + (MR_nonnull NSFetchRequest *) MR_requestFirstByAttribute:(MR_nonnull NSString *)attribute withValue:(MR_nullable id)searchValue; 26 | + (MR_nonnull NSFetchRequest *) MR_requestFirstByAttribute:(MR_nonnull NSString *)attribute withValue:(MR_nullable id)searchValue inContext:(MR_nonnull NSManagedObjectContext *)context; 27 | + (MR_nonnull NSFetchRequest *) MR_requestAllSortedBy:(MR_nonnull NSString *)sortTerm ascending:(BOOL)ascending; 28 | + (MR_nonnull NSFetchRequest *) MR_requestAllSortedBy:(MR_nonnull NSString *)sortTerm ascending:(BOOL)ascending inContext:(MR_nonnull NSManagedObjectContext *)context; 29 | + (MR_nonnull NSFetchRequest *) MR_requestAllSortedBy:(MR_nonnull NSString *)sortTerm ascending:(BOOL)ascending withPredicate:(MR_nullable NSPredicate *)searchTerm; 30 | + (MR_nonnull NSFetchRequest *) MR_requestAllSortedBy:(MR_nonnull NSString *)sortTerm ascending:(BOOL)ascending withPredicate:(MR_nullable NSPredicate *)searchTerm inContext:(MR_nonnull NSManagedObjectContext *)context; 31 | 32 | @end 33 | -------------------------------------------------------------------------------- /MagicalRecord/Categories/NSManagedObjectContext/NSManagedObjectContext+MagicalChainSave.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSManagedObjectContext+MagicalChainSave.h 3 | // Magical Record 4 | // 5 | // Created by Lee on 8/27/14. 6 | // Copyright (c) 2014 Magical Panda Software LLC. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | #import 12 | 13 | @interface NSManagedObjectContext (MagicalRecordChainSave) 14 | /** 15 | Creates a child context for the current context that you can make changes within, before saving up through all parent contexts to the main queue context, and finally to the saving context. This method will return immediately, and execute the save initially on a background thread, and then on the appropriate thread for each context it saves. 16 | 17 | @param block Block that is passed a managed object context. 18 | */ 19 | - (void)MR_saveWithBlock:(void (^ __MR_nonnull)(NSManagedObjectContext * __MR_nonnull localContext))block; 20 | 21 | /** 22 | Creates a child context for the current context that you can make changes within, before saving up through all parent contexts to the main queue context, and finally to the saving context. This method will return immediately, and execute the save initially on a background thread, and then on the appropriate thread for each context it saves. 23 | 24 | @param block Block that is passed a managed object context. 25 | @param completion Completion block that is called once all contexts have been saved, or if an error is encountered. 26 | */ 27 | - (void)MR_saveWithBlock:(void (^ __MR_nonnull)(NSManagedObjectContext * __MR_nonnull localContext))block completion:(MR_nullable MRSaveCompletionHandler)completion; 28 | 29 | /** 30 | Creates a child context for the current context that you can make changes within, before saving up through all parent contexts to the main queue context, and finally to the saving context. This method will not return until the save has completed, blocking the thread it is called on. 31 | 32 | @param block Block that is passed a managed object context. 33 | */ 34 | - (void)MR_saveWithBlockAndWait:(void (^ __MR_nonnull)(NSManagedObjectContext * __MR_nonnull localContext))block; 35 | 36 | @end 37 | -------------------------------------------------------------------------------- /MagicalRecord/Categories/NSManagedObjectContext/NSManagedObjectContext+MagicalChainSave.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSManagedObjectContext+MagicalChainSave.m 3 | // Magical Record 4 | // 5 | // Created by Lee on 8/27/14. 6 | // Copyright (c) 2014 Magical Panda Software LLC. All rights reserved. 7 | // 8 | 9 | #import "NSManagedObjectContext+MagicalChainSave.h" 10 | #import "NSManagedObjectContext+MagicalRecord.h" 11 | 12 | @implementation NSManagedObjectContext (MagicalRecord_ChainSave) 13 | - (void)MR_saveWithBlock:(void (^)(NSManagedObjectContext *localContext))block 14 | { 15 | [self MR_saveWithBlock:block completion:nil]; 16 | } 17 | 18 | - (void)MR_saveWithBlock:(void (^)(NSManagedObjectContext *localContext))block completion:(MRSaveCompletionHandler)completion 19 | { 20 | NSManagedObjectContext *localContext = [NSManagedObjectContext MR_contextWithParent:self]; 21 | 22 | [localContext performBlock:^{ 23 | [localContext MR_setWorkingName:NSStringFromSelector(_cmd)]; 24 | 25 | if (block) { 26 | block(localContext); 27 | } 28 | 29 | [localContext MR_saveWithOptions:MRSaveParentContexts completion:completion]; 30 | }]; 31 | } 32 | 33 | #pragma mark - Synchronous saving 34 | 35 | - (void)MR_saveWithBlockAndWait:(void (^)(NSManagedObjectContext *localContext))block 36 | { 37 | NSManagedObjectContext *localContext = [NSManagedObjectContext MR_contextWithParent:self]; 38 | 39 | [localContext performBlockAndWait:^{ 40 | [localContext MR_setWorkingName:NSStringFromSelector(_cmd)]; 41 | 42 | if (block) { 43 | block(localContext); 44 | } 45 | 46 | [localContext MR_saveWithOptions:MRSaveParentContexts|MRSaveSynchronously completion:nil]; 47 | }]; 48 | } 49 | 50 | @end 51 | -------------------------------------------------------------------------------- /MagicalRecord/Categories/NSManagedObjectContext/NSManagedObjectContext+MagicalObserving.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSManagedObjectContext+MagicalObserving.h 3 | // Magical Record 4 | // 5 | // Created by Saul Mora on 3/9/12. 6 | // Copyright (c) 2012 Magical Panda Software LLC. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | OBJC_EXPORT NSString * __MR_nonnull const kMagicalRecordDidMergeChangesFromiCloudNotification; 13 | 14 | /** 15 | Category methods to aid in observing changes in other contexts. 16 | 17 | @since Available in v2.0 and later. 18 | */ 19 | @interface NSManagedObjectContext (MagicalObserving) 20 | 21 | /** 22 | Merge changes from another context into self. 23 | 24 | @param otherContext Managed object context to observe. 25 | 26 | @since Available in v2.0 and later. 27 | */ 28 | - (void) MR_observeContext:(MR_nonnull NSManagedObjectContext *)otherContext; 29 | 30 | /** 31 | Stops merging changes from the supplied context into self. 32 | 33 | @param otherContext Managed object context to stop observing. 34 | 35 | @since Available in v2.0 and later. 36 | */ 37 | - (void) MR_stopObservingContext:(MR_nonnull NSManagedObjectContext *)otherContext; 38 | 39 | /** 40 | Merges changes from another context into self on the main thread. 41 | 42 | @param otherContext Managed object context to observe. 43 | 44 | @since Available in v2.0 and later. 45 | */ 46 | - (void) MR_observeContextOnMainThread:(MR_nonnull NSManagedObjectContext *)otherContext; 47 | 48 | #if TARGET_OS_OSX || TARGET_OS_IOS 49 | 50 | /** 51 | Merges changes from the supplied persistent store coordinator into self in response to changes from iCloud. 52 | 53 | @param coordinator Persistent store coordinator 54 | 55 | @see -MR_stopObservingiCloudChangesInCoordinator: 56 | 57 | @since Available in v2.0 and later. 58 | */ 59 | - (void) MR_observeiCloudChangesInCoordinator:(MR_nonnull NSPersistentStoreCoordinator *)coordinator; 60 | 61 | /** 62 | Stops observation and merging of changes from the supplied persistent store coordinator in response to changes from iCloud. 63 | 64 | @param coordinator Persistent store coordinator 65 | 66 | @see -MR_observeiCloudChangesInCoordinator: 67 | 68 | @since Available in v2.0 and later. 69 | */ 70 | - (void) MR_stopObservingiCloudChangesInCoordinator:(MR_nonnull NSPersistentStoreCoordinator *)coordinator; 71 | 72 | #endif 73 | 74 | @end 75 | -------------------------------------------------------------------------------- /MagicalRecord/Categories/NSManagedObjectContext/NSManagedObjectContext+MagicalThreading.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSManagedObjectContext+MagicalThreading.h 3 | // Magical Record 4 | // 5 | // Created by Saul Mora on 3/9/12. 6 | // Copyright (c) 2012 Magical Panda Software LLC. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface NSManagedObjectContext (MagicalThreading) 13 | 14 | + (MR_nonnull NSManagedObjectContext *) MR_contextForCurrentThread __attribute((deprecated("This method will be removed in MagicalRecord 3.0"))); 15 | + (void) MR_clearNonMainThreadContextsCache __attribute((deprecated("This method will be removed in MagicalRecord 3.0"))); 16 | + (void) MR_resetContextForCurrentThread __attribute((deprecated("This method will be removed in MagicalRecord 3.0"))); 17 | + (void) MR_clearContextForCurrentThread __attribute((deprecated("This method will be removed in MagicalRecord 3.0"))); 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /MagicalRecord/Categories/NSManagedObjectModel+MagicalRecord.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSManagedObjectModel+MagicalRecord.h 3 | // 4 | // Created by Saul Mora on 3/11/10. 5 | // Copyright 2010 Magical Panda Software, LLC All rights reserved. 6 | // 7 | 8 | #import 9 | #import 10 | 11 | @interface NSManagedObjectModel (MagicalRecord) 12 | 13 | + (MR_nullable NSManagedObjectModel *) MR_defaultManagedObjectModel; 14 | 15 | + (void) MR_setDefaultManagedObjectModel:(MR_nullable NSManagedObjectModel *)newDefaultModel; 16 | 17 | + (MR_nullable NSManagedObjectModel *) MR_mergedObjectModelFromMainBundle; 18 | + (MR_nullable NSManagedObjectModel *) MR_newManagedObjectModelNamed:(MR_nonnull NSString *)modelFileName NS_RETURNS_RETAINED; 19 | + (MR_nullable NSManagedObjectModel *) MR_managedObjectModelNamed:(MR_nonnull NSString *)modelFileName; 20 | + (MR_nullable NSManagedObjectModel *) MR_newModelNamed:(MR_nonnull NSString *) modelName inBundleNamed:(MR_nonnull NSString *) bundleName NS_RETURNS_RETAINED; 21 | + (MR_nullable NSManagedObjectModel *) MR_newModelNamed:(MR_nonnull NSString *) modelName inBundle:(MR_nonnull NSBundle*) bundle NS_RETURNS_RETAINED; 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /MagicalRecord/Categories/NSManagedObjectModel+MagicalRecord.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSManagedObjectModel+MagicalRecord.m 3 | // 4 | // Created by Saul Mora on 3/11/10. 5 | // Copyright 2010 Magical Panda Software, LLC All rights reserved. 6 | // 7 | 8 | #import "NSManagedObjectModel+MagicalRecord.h" 9 | #import "MagicalRecord+Options.h" 10 | 11 | static NSManagedObjectModel *defaultManagedObjectModel_ = nil; 12 | 13 | @implementation NSManagedObjectModel (MagicalRecord) 14 | 15 | + (NSManagedObjectModel *) MR_defaultManagedObjectModel 16 | { 17 | if (defaultManagedObjectModel_ == nil && [MagicalRecord shouldAutoCreateManagedObjectModel]) 18 | { 19 | [self MR_setDefaultManagedObjectModel:[self MR_mergedObjectModelFromMainBundle]]; 20 | } 21 | return defaultManagedObjectModel_; 22 | } 23 | 24 | + (void) MR_setDefaultManagedObjectModel:(NSManagedObjectModel *)newDefaultModel 25 | { 26 | defaultManagedObjectModel_ = newDefaultModel; 27 | } 28 | 29 | + (NSManagedObjectModel *) MR_mergedObjectModelFromMainBundle 30 | { 31 | return [self mergedModelFromBundles:nil]; 32 | } 33 | 34 | + (NSManagedObjectModel *) MR_newModelNamed:(NSString *) modelName inBundleNamed:(NSString *) bundleName 35 | { 36 | NSString *path = [[NSBundle mainBundle] pathForResource:[modelName stringByDeletingPathExtension] 37 | ofType:[modelName pathExtension] 38 | inDirectory:bundleName]; 39 | NSURL *modelUrl = [NSURL fileURLWithPath:path]; 40 | 41 | NSManagedObjectModel *mom = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelUrl]; 42 | 43 | return mom; 44 | } 45 | 46 | + (NSManagedObjectModel *) MR_newModelNamed:(NSString *) modelName inBundle:(NSBundle*) bundle 47 | { 48 | NSString *path = [bundle pathForResource:[modelName stringByDeletingPathExtension] 49 | ofType:[modelName pathExtension]]; 50 | NSURL *modelUrl = [NSURL fileURLWithPath:path]; 51 | 52 | NSManagedObjectModel *mom = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelUrl]; 53 | 54 | return mom; 55 | } 56 | 57 | + (NSManagedObjectModel *) MR_newManagedObjectModelNamed:(NSString *)modelFileName 58 | { 59 | NSString *path = [[NSBundle mainBundle] pathForResource:[modelFileName stringByDeletingPathExtension] 60 | ofType:[modelFileName pathExtension]]; 61 | NSURL *momURL = [NSURL fileURLWithPath:path]; 62 | 63 | NSManagedObjectModel *model = [[NSManagedObjectModel alloc] initWithContentsOfURL:momURL]; 64 | return model; 65 | } 66 | 67 | + (NSManagedObjectModel *) MR_managedObjectModelNamed:(NSString *)modelFileName 68 | { 69 | NSManagedObjectModel *model = [self MR_newManagedObjectModelNamed:modelFileName]; 70 | return model; 71 | } 72 | 73 | @end 74 | -------------------------------------------------------------------------------- /MagicalRecord/Categories/NSPersistentStore+MagicalRecord.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSPersistentStore+MagicalRecord.h 3 | // 4 | // Created by Saul Mora on 3/11/10. 5 | // Copyright 2010 Magical Panda Software, LLC All rights reserved. 6 | // 7 | 8 | #import 9 | #import 10 | #import "MagicalRecordDeprecationMacros.h" 11 | 12 | // option to autodelete store if it already exists 13 | 14 | OBJC_EXPORT NSString * __MR_nonnull const kMagicalRecordDefaultStoreFileName; 15 | 16 | 17 | @interface NSPersistentStore (MagicalRecord) 18 | 19 | + (MR_nonnull NSURL *) MR_defaultLocalStoreUrl; 20 | 21 | + (MR_nullable NSPersistentStore *) MR_defaultPersistentStore; 22 | + (void) MR_setDefaultPersistentStore:(MR_nullable NSPersistentStore *) store; 23 | 24 | + (MR_nullable NSURL *) MR_urlForStoreName:(MR_nonnull NSString *)storeFileName; 25 | + (MR_nullable NSURL *) MR_cloudURLForUbiquitousContainer:(MR_nonnull NSString *)bucketName; 26 | + (MR_nullable NSURL *) MR_cloudURLForUbiqutiousContainer:(MR_nonnull NSString *)bucketName MR_DEPRECATED_WILL_BE_REMOVED_IN_PLEASE_USE("4.0", "MR_cloudURLForUbiquitousContainer:"); 27 | 28 | @end 29 | 30 | 31 | -------------------------------------------------------------------------------- /MagicalRecord/Categories/NSPersistentStore+MagicalRecord.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSPersistentStore+MagicalRecord.m 3 | // 4 | // Created by Saul Mora on 3/11/10. 5 | // Copyright 2010 Magical Panda Software, LLC All rights reserved. 6 | // 7 | 8 | #import "NSPersistentStore+MagicalRecord.h" 9 | 10 | NSString * const kMagicalRecordDefaultStoreFileName = @"CoreDataStore.sqlite"; 11 | 12 | static NSPersistentStore *defaultPersistentStore_ = nil; 13 | 14 | 15 | @implementation NSPersistentStore (MagicalRecord) 16 | 17 | + (NSPersistentStore *) MR_defaultPersistentStore 18 | { 19 | return defaultPersistentStore_; 20 | } 21 | 22 | + (void) MR_setDefaultPersistentStore:(NSPersistentStore *)store 23 | { 24 | defaultPersistentStore_ = store; 25 | } 26 | 27 | + (NSString *) MR_directory:(NSSearchPathDirectory)type 28 | { 29 | return [NSSearchPathForDirectoriesInDomains(type, NSUserDomainMask, YES) lastObject]; 30 | } 31 | 32 | + (NSString *)MR_applicationDocumentsDirectory 33 | { 34 | return [self MR_directory:NSDocumentDirectory]; 35 | } 36 | 37 | + (NSString *)MR_applicationStorageDirectory 38 | { 39 | NSString *applicationName = [[[NSBundle mainBundle] infoDictionary] valueForKey:(NSString *)kCFBundleNameKey]; 40 | return [[self MR_directory:NSApplicationSupportDirectory] stringByAppendingPathComponent:applicationName]; 41 | } 42 | 43 | + (NSURL *) MR_urlForStoreName:(NSString *)storeFileName 44 | { 45 | NSString *pathForStoreName = [[self MR_applicationStorageDirectory] stringByAppendingPathComponent:storeFileName]; 46 | return [NSURL fileURLWithPath:pathForStoreName]; 47 | } 48 | 49 | + (NSURL *) MR_cloudURLForUbiquitousContainer:(NSString *)bucketName 50 | { 51 | NSFileManager *fileManager = [[NSFileManager alloc] init]; 52 | NSURL *cloudURL = nil; 53 | if ([fileManager respondsToSelector:@selector(URLForUbiquityContainerIdentifier:)]) 54 | { 55 | cloudURL = [fileManager URLForUbiquityContainerIdentifier:bucketName]; 56 | } 57 | 58 | return cloudURL; 59 | } 60 | 61 | + (NSURL *) MR_cloudURLForUbiqutiousContainer:(NSString *)bucketName 62 | { 63 | return [self MR_cloudURLForUbiquitousContainer:bucketName]; 64 | } 65 | 66 | + (NSURL *) MR_defaultLocalStoreUrl 67 | { 68 | return [self MR_urlForStoreName:kMagicalRecordDefaultStoreFileName]; 69 | } 70 | 71 | @end 72 | -------------------------------------------------------------------------------- /MagicalRecord/Core/MagicalRecord+Actions.h: -------------------------------------------------------------------------------- 1 | // 2 | // MagicalRecord+Actions.h 3 | // 4 | // Created by Saul Mora on 2/24/11. 5 | // Copyright 2011 Magical Panda Software. All rights reserved. 6 | // 7 | 8 | #import 9 | #import 10 | #import 11 | #import 12 | #import 13 | 14 | @interface MagicalRecord (Actions) 15 | 16 | /* For all background saving operations. These calls will be sent to a different thread/queue. 17 | */ 18 | + (void) saveWithBlock:(void (^ __MR_nonnull)(NSManagedObjectContext * __MR_nonnull localContext))block; 19 | + (void) saveWithBlock:(void (^ __MR_nonnull)(NSManagedObjectContext * __MR_nonnull localContext))block completion:(MR_nullable MRSaveCompletionHandler)completion; 20 | 21 | /* For saving on the current thread as the caller, only with a separate context. Useful when you're managing your own threads/queues and need a serial call to create or change data 22 | */ 23 | + (void) saveWithBlockAndWait:(void (^ __MR_nonnull)(NSManagedObjectContext * __MR_nonnull localContext))block; 24 | 25 | @end 26 | 27 | @interface MagicalRecord (ActionsDeprecated) 28 | 29 | + (void) saveUsingCurrentThreadContextWithBlock:(void (^ __MR_nonnull)(NSManagedObjectContext * __MR_nonnull localContext))block completion:(MR_nullable MRSaveCompletionHandler)completion MR_DEPRECATED_WILL_BE_REMOVED_IN("3.0"); 30 | + (void) saveUsingCurrentThreadContextWithBlockAndWait:(void (^ __MR_nonnull)(NSManagedObjectContext * __MR_nonnull localContext))block MR_DEPRECATED_WILL_BE_REMOVED_IN("3.0"); 31 | + (void) saveInBackgroundWithBlock:(void (^ __MR_nonnull)(NSManagedObjectContext * __MR_nonnull localContext))block MR_DEPRECATED_WILL_BE_REMOVED_IN("3.0"); 32 | + (void) saveInBackgroundWithBlock:(void (^ __MR_nonnull)(NSManagedObjectContext * __MR_nonnull localContext))block completion:(void (^ __MR_nullable)(void))completion MR_DEPRECATED_WILL_BE_REMOVED_IN("3.0"); 33 | + (void) saveInBackgroundUsingCurrentContextWithBlock:(void (^ __MR_nonnull)(NSManagedObjectContext * __MR_nonnull localContext))block completion:(void (^ __MR_nullable)(void))completion errorHandler:(void (^ __MR_nullable)(NSError * __MR_nullable error))errorHandler MR_DEPRECATED_WILL_BE_REMOVED_IN("3.0"); 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /MagicalRecord/Core/MagicalRecord+ErrorHandling.h: -------------------------------------------------------------------------------- 1 | // 2 | // MagicalRecord+ErrorHandling.h 3 | // Magical Record 4 | // 5 | // Created by Saul Mora on 3/6/12. 6 | // Copyright (c) 2012 Magical Panda Software LLC. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface MagicalRecord (ErrorHandling) 13 | 14 | + (void) handleErrors:(MR_nonnull NSError *)error; 15 | 16 | + (void) setErrorHandlerTarget:(MR_nullable id)target action:(MR_nonnull SEL)action; 17 | + (MR_nonnull SEL) errorHandlerAction; 18 | + (MR_nullable id) errorHandlerTarget; 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /MagicalRecord/Core/MagicalRecord+ErrorHandling.m: -------------------------------------------------------------------------------- 1 | // 2 | // MagicalRecord+ErrorHandling.m 3 | // Magical Record 4 | // 5 | // Created by Saul Mora on 3/6/12. 6 | // Copyright (c) 2012 Magical Panda Software LLC. All rights reserved. 7 | // 8 | 9 | #import "MagicalRecord+ErrorHandling.h" 10 | #import "MagicalRecordLogging.h" 11 | 12 | 13 | __weak static id errorHandlerTarget = nil; 14 | static SEL errorHandlerAction = nil; 15 | 16 | 17 | @implementation MagicalRecord (ErrorHandling) 18 | 19 | + (void) cleanUpErrorHanding 20 | { 21 | errorHandlerTarget = nil; 22 | errorHandlerAction = nil; 23 | } 24 | 25 | + (void) defaultErrorHandler:(NSError *)error 26 | { 27 | NSDictionary *userInfo = [error userInfo]; 28 | for (NSArray *detailedError in [userInfo allValues]) 29 | { 30 | if ([detailedError isKindOfClass:[NSArray class]]) 31 | { 32 | for (NSError *e in detailedError) 33 | { 34 | if ([e respondsToSelector:@selector(userInfo)]) 35 | { 36 | MRLogError(@"Error Details: %@", [e userInfo]); 37 | } 38 | else 39 | { 40 | MRLogError(@"Error Details: %@", e); 41 | } 42 | } 43 | } 44 | else 45 | { 46 | MRLogError(@"Error: %@", detailedError); 47 | } 48 | } 49 | MRLogError(@"Error Message: %@", [error localizedDescription]); 50 | MRLogError(@"Error Domain: %@", [error domain]); 51 | MRLogError(@"Recovery Suggestion: %@", [error localizedRecoverySuggestion]); 52 | } 53 | 54 | + (void) handleErrors:(NSError *)error 55 | { 56 | if (error) 57 | { 58 | // If a custom error handler is set, call that 59 | if (errorHandlerTarget != nil && errorHandlerAction != nil) 60 | { 61 | #pragma clang diagnostic push 62 | #pragma clang diagnostic ignored "-Warc-performSelector-leaks" 63 | [errorHandlerTarget performSelector:errorHandlerAction withObject:error]; 64 | #pragma clang diagnostic pop 65 | } 66 | else 67 | { 68 | // Otherwise, fall back to the default error handling 69 | [self defaultErrorHandler:error]; 70 | } 71 | } 72 | } 73 | 74 | + (id) errorHandlerTarget 75 | { 76 | return errorHandlerTarget; 77 | } 78 | 79 | + (SEL) errorHandlerAction 80 | { 81 | return errorHandlerAction; 82 | } 83 | 84 | + (void) setErrorHandlerTarget:(id)target action:(SEL)action 85 | { 86 | errorHandlerTarget = target; /* Deliberately don't retain to avoid potential retain cycles */ 87 | errorHandlerAction = action; 88 | } 89 | 90 | @end 91 | -------------------------------------------------------------------------------- /MagicalRecord/Core/MagicalRecord+Options.m: -------------------------------------------------------------------------------- 1 | // 2 | // MagicalRecord+Options.m 3 | // Magical Record 4 | // 5 | // Created by Saul Mora on 3/6/12. 6 | // Copyright (c) 2012 Magical Panda Software LLC. All rights reserved. 7 | // 8 | 9 | #import "MagicalRecord+Options.h" 10 | 11 | #ifdef DEBUG 12 | static MagicalRecordLoggingLevel kMagicalRecordLoggingLevel = MagicalRecordLoggingLevelDebug; 13 | #else 14 | static MagicalRecordLoggingLevel kMagicalRecordLoggingLevel = MagicalRecordLoggingLevelError; 15 | #endif 16 | static BOOL kMagicalRecordShouldAutoCreateManagedObjectModel = YES; 17 | static BOOL kMagicalRecordShouldAutoCreateDefaultPersistentStoreCoordinator = NO; 18 | #ifdef DEBUG 19 | static BOOL kMagicalRecordShouldDeleteStoreOnModelMismatch = YES; 20 | #else 21 | static BOOL kMagicalRecordShouldDeleteStoreOnModelMismatch = NO; 22 | #endif 23 | 24 | @implementation MagicalRecord (Options) 25 | 26 | #pragma mark - Configuration Options 27 | 28 | + (BOOL) shouldAutoCreateManagedObjectModel 29 | { 30 | return kMagicalRecordShouldAutoCreateManagedObjectModel; 31 | } 32 | 33 | + (void) setShouldAutoCreateManagedObjectModel:(BOOL)autoCreate 34 | { 35 | kMagicalRecordShouldAutoCreateManagedObjectModel = autoCreate; 36 | } 37 | 38 | + (BOOL) shouldAutoCreateDefaultPersistentStoreCoordinator 39 | { 40 | return kMagicalRecordShouldAutoCreateDefaultPersistentStoreCoordinator; 41 | } 42 | 43 | + (void) setShouldAutoCreateDefaultPersistentStoreCoordinator:(BOOL)autoCreate 44 | { 45 | kMagicalRecordShouldAutoCreateDefaultPersistentStoreCoordinator = autoCreate; 46 | } 47 | 48 | + (BOOL) shouldDeleteStoreOnModelMismatch 49 | { 50 | return kMagicalRecordShouldDeleteStoreOnModelMismatch; 51 | } 52 | 53 | + (void) setShouldDeleteStoreOnModelMismatch:(BOOL)shouldDelete 54 | { 55 | kMagicalRecordShouldDeleteStoreOnModelMismatch = shouldDelete; 56 | } 57 | 58 | + (MagicalRecordLoggingLevel) loggingLevel 59 | { 60 | return kMagicalRecordLoggingLevel; 61 | } 62 | 63 | + (void) setLoggingLevel:(MagicalRecordLoggingLevel)level 64 | { 65 | kMagicalRecordLoggingLevel = level; 66 | } 67 | 68 | @end 69 | -------------------------------------------------------------------------------- /MagicalRecord/Core/MagicalRecord+Setup.h: -------------------------------------------------------------------------------- 1 | // 2 | // MagicalRecord+Setup.h 3 | // Magical Record 4 | // 5 | // Created by Saul Mora on 3/7/12. 6 | // Copyright (c) 2012 Magical Panda Software LLC. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface MagicalRecord (Setup) 13 | 14 | + (void) setupCoreDataStack; 15 | + (void) setupCoreDataStackWithInMemoryStore; 16 | + (void) setupAutoMigratingCoreDataStack; 17 | 18 | + (void) setupCoreDataStackWithStoreNamed:(MR_nonnull NSString *)storeName; 19 | + (void) setupCoreDataStackWithAutoMigratingSqliteStoreNamed:(MR_nonnull NSString *)storeName; 20 | 21 | + (void) setupCoreDataStackWithStoreAtURL:(MR_nonnull NSURL *)storeURL; 22 | + (void) setupCoreDataStackWithAutoMigratingSqliteStoreAtURL:(MR_nonnull NSURL *)storeURL; 23 | 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /MagicalRecord/Core/MagicalRecord+Setup.m: -------------------------------------------------------------------------------- 1 | // 2 | // MagicalRecord+Setup.m 3 | // Magical Record 4 | // 5 | // Created by Saul Mora on 3/7/12. 6 | // Copyright (c) 2012 Magical Panda Software LLC. All rights reserved. 7 | // 8 | 9 | #import "MagicalRecord+Setup.h" 10 | #import "NSManagedObject+MagicalRecord.h" 11 | #import "NSPersistentStoreCoordinator+MagicalRecord.h" 12 | #import "NSManagedObjectContext+MagicalRecord.h" 13 | 14 | @implementation MagicalRecord (Setup) 15 | 16 | + (void) setupCoreDataStack 17 | { 18 | [self setupCoreDataStackWithStoreNamed:[self defaultStoreName]]; 19 | } 20 | 21 | + (void) setupAutoMigratingCoreDataStack 22 | { 23 | [self setupCoreDataStackWithAutoMigratingSqliteStoreNamed:[self defaultStoreName]]; 24 | } 25 | 26 | + (void) setupCoreDataStackWithStoreNamed:(NSString *)storeName 27 | { 28 | if ([NSPersistentStoreCoordinator MR_defaultStoreCoordinator] != nil) return; 29 | 30 | NSPersistentStoreCoordinator *coordinator = [NSPersistentStoreCoordinator MR_coordinatorWithSqliteStoreNamed:storeName]; 31 | [NSPersistentStoreCoordinator MR_setDefaultStoreCoordinator:coordinator]; 32 | 33 | [NSManagedObjectContext MR_initializeDefaultContextWithCoordinator:coordinator]; 34 | } 35 | 36 | + (void) setupCoreDataStackWithAutoMigratingSqliteStoreNamed:(NSString *)storeName 37 | { 38 | if ([NSPersistentStoreCoordinator MR_defaultStoreCoordinator] != nil) return; 39 | 40 | NSPersistentStoreCoordinator *coordinator = [NSPersistentStoreCoordinator MR_coordinatorWithAutoMigratingSqliteStoreNamed:storeName]; 41 | [NSPersistentStoreCoordinator MR_setDefaultStoreCoordinator:coordinator]; 42 | 43 | [NSManagedObjectContext MR_initializeDefaultContextWithCoordinator:coordinator]; 44 | } 45 | 46 | + (void) setupCoreDataStackWithStoreAtURL:(NSURL *)storeURL 47 | { 48 | if ([NSPersistentStoreCoordinator MR_defaultStoreCoordinator] != nil) return; 49 | 50 | NSPersistentStoreCoordinator *coordinator = [NSPersistentStoreCoordinator MR_coordinatorWithSqliteStoreAtURL:storeURL]; 51 | [NSPersistentStoreCoordinator MR_setDefaultStoreCoordinator:coordinator]; 52 | 53 | [NSManagedObjectContext MR_initializeDefaultContextWithCoordinator:coordinator]; 54 | } 55 | 56 | + (void) setupCoreDataStackWithAutoMigratingSqliteStoreAtURL:(NSURL *)storeURL 57 | { 58 | if ([NSPersistentStoreCoordinator MR_defaultStoreCoordinator] != nil) return; 59 | 60 | NSPersistentStoreCoordinator *coordinator = [NSPersistentStoreCoordinator MR_coordinatorWithAutoMigratingSqliteStoreAtURL:storeURL]; 61 | [NSPersistentStoreCoordinator MR_setDefaultStoreCoordinator:coordinator]; 62 | 63 | [NSManagedObjectContext MR_initializeDefaultContextWithCoordinator:coordinator]; 64 | } 65 | 66 | + (void) setupCoreDataStackWithInMemoryStore 67 | { 68 | if ([NSPersistentStoreCoordinator MR_defaultStoreCoordinator] != nil) return; 69 | 70 | NSPersistentStoreCoordinator *coordinator = [NSPersistentStoreCoordinator MR_coordinatorWithInMemoryStore]; 71 | [NSPersistentStoreCoordinator MR_setDefaultStoreCoordinator:coordinator]; 72 | 73 | [NSManagedObjectContext MR_initializeDefaultContextWithCoordinator:coordinator]; 74 | } 75 | 76 | @end 77 | -------------------------------------------------------------------------------- /MagicalRecord/Core/MagicalRecord+ShorthandMethods.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2015 Magical Panda Software LLC. All rights reserved. 3 | 4 | #import 5 | 6 | @interface MagicalRecord (ShorthandMethods) 7 | 8 | + (void)enableShorthandMethods; 9 | 10 | @end 11 | -------------------------------------------------------------------------------- /MagicalRecord/Core/MagicalRecord+iCloud.h: -------------------------------------------------------------------------------- 1 | // 2 | // MagicalRecord+iCloud.h 3 | // Magical Record 4 | // 5 | // Created by Saul Mora on 3/7/12. 6 | // Copyright (c) 2012 Magical Panda Software LLC. All rights reserved. 7 | // 8 | 9 | #include 10 | #if TARGET_OS_OSX || TARGET_OS_IOS 11 | #import 12 | #import 13 | 14 | @interface MagicalRecord (iCloud) 15 | 16 | + (BOOL)isICloudEnabled; 17 | 18 | + (void)setupCoreDataStackWithiCloudContainer:(MR_nonnull NSString *)containerID 19 | localStoreNamed:(MR_nonnull NSString *)localStore; 20 | 21 | + (void)setupCoreDataStackWithiCloudContainer:(MR_nonnull NSString *)containerID 22 | contentNameKey:(MR_nullable NSString *)contentNameKey 23 | localStoreNamed:(MR_nonnull NSString *)localStoreName 24 | cloudStorePathComponent:(MR_nullable NSString *)pathSubcomponent; 25 | 26 | + (void)setupCoreDataStackWithiCloudContainer:(MR_nonnull NSString *)containerID 27 | contentNameKey:(MR_nullable NSString *)contentNameKey 28 | localStoreNamed:(MR_nonnull NSString *)localStoreName 29 | cloudStorePathComponent:(MR_nullable NSString *)pathSubcomponent 30 | completion:(void (^ __MR_nullable)(void))completion; 31 | 32 | + (void)setupCoreDataStackWithiCloudContainer:(MR_nonnull NSString *)containerID 33 | localStoreAtURL:(MR_nonnull NSURL *)storeURL; 34 | 35 | + (void)setupCoreDataStackWithiCloudContainer:(MR_nonnull NSString *)containerID 36 | contentNameKey:(MR_nullable NSString *)contentNameKey 37 | localStoreAtURL:(MR_nonnull NSURL *)storeURL 38 | cloudStorePathComponent:(MR_nullable NSString *)pathSubcomponent; 39 | 40 | + (void)setupCoreDataStackWithiCloudContainer:(MR_nonnull NSString *)containerID 41 | contentNameKey:(MR_nullable NSString *)contentNameKey 42 | localStoreAtURL:(MR_nonnull NSURL *)storeURL 43 | cloudStorePathComponent:(MR_nullable NSString *)pathSubcomponent 44 | completion:(void (^ __MR_nullable)(void))completion; 45 | 46 | @end 47 | #endif 48 | -------------------------------------------------------------------------------- /MagicalRecord/Core/MagicalRecordDeprecationMacros.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Tony Arnold on 10/04/2014. 3 | // Copyright (c) 2014 Magical Panda Software LLC. All rights reserved. 4 | // 5 | 6 | #define MR_DEPRECATED_WILL_BE_REMOVED_IN(VERSION) __attribute__((deprecated("This method has been deprecated and will be removed in MagicalRecord " VERSION "."))) 7 | #define MR_DEPRECATED_WILL_BE_REMOVED_IN_PLEASE_USE(VERSION, METHOD) __attribute__((deprecated("This method has been deprecated and will be removed in MagicalRecord " VERSION ". Please use `" METHOD "` instead."))) 8 | -------------------------------------------------------------------------------- /MagicalRecord/Core/MagicalRecordInternal.m: -------------------------------------------------------------------------------- 1 | // 2 | // MagicalRecord.m 3 | // 4 | // Created by Saul Mora on 3/11/10. 5 | // Copyright 2010 Magical Panda Software, LLC All rights reserved. 6 | // 7 | 8 | #import "MagicalRecord.h" 9 | 10 | NSString * const kMagicalRecordCleanedUpNotification = @"kMagicalRecordCleanedUpNotification"; 11 | 12 | @interface MagicalRecord (Internal) 13 | 14 | + (void) cleanUpStack; 15 | + (void) cleanUpErrorHanding; 16 | 17 | @end 18 | 19 | @interface NSManagedObjectContext (MagicalRecordInternal) 20 | 21 | + (void) MR_cleanUp; 22 | 23 | @end 24 | 25 | 26 | @implementation MagicalRecord 27 | 28 | + (MagicalRecordVersionTag) version 29 | { 30 | return MagicalRecordVersionTag2_3; 31 | } 32 | 33 | + (void) cleanUp 34 | { 35 | [self cleanUpErrorHanding]; 36 | [self cleanUpStack]; 37 | NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter]; 38 | [notificationCenter postNotificationName:kMagicalRecordCleanedUpNotification 39 | object:nil 40 | userInfo:nil]; 41 | } 42 | 43 | + (void) cleanUpStack 44 | { 45 | [NSManagedObjectContext MR_cleanUp]; 46 | [NSManagedObjectModel MR_setDefaultManagedObjectModel:nil]; 47 | [NSPersistentStoreCoordinator MR_setDefaultStoreCoordinator:nil]; 48 | [NSPersistentStore MR_setDefaultPersistentStore:nil]; 49 | } 50 | 51 | + (NSString *) currentStack 52 | { 53 | NSMutableString *status = [NSMutableString stringWithString:@"Current Default Core Data Stack: ---- \n"]; 54 | 55 | [status appendFormat:@"Model: %@\n", [[NSManagedObjectModel MR_defaultManagedObjectModel] entityVersionHashesByName]]; 56 | [status appendFormat:@"Coordinator: %@\n", [NSPersistentStoreCoordinator MR_defaultStoreCoordinator]]; 57 | [status appendFormat:@"Store: %@\n", [NSPersistentStore MR_defaultPersistentStore]]; 58 | [status appendFormat:@"Default Context: %@\n", [[NSManagedObjectContext MR_defaultContext] MR_description]]; 59 | [status appendFormat:@"Context Chain: \n%@\n", [[NSManagedObjectContext MR_defaultContext] MR_parentChain]]; 60 | 61 | return status; 62 | } 63 | 64 | + (void) setDefaultModelNamed:(NSString *)modelName 65 | { 66 | NSManagedObjectModel *model = [NSManagedObjectModel MR_managedObjectModelNamed:modelName]; 67 | [NSManagedObjectModel MR_setDefaultManagedObjectModel:model]; 68 | } 69 | 70 | + (void) setDefaultModelFromClass:(Class)modelClass 71 | { 72 | NSBundle *bundle = [NSBundle bundleForClass:modelClass]; 73 | NSManagedObjectModel *model = [NSManagedObjectModel mergedModelFromBundles:[NSArray arrayWithObject:bundle]]; 74 | [NSManagedObjectModel MR_setDefaultManagedObjectModel:model]; 75 | } 76 | 77 | + (NSString *) defaultStoreName 78 | { 79 | NSString *defaultName = [[[NSBundle mainBundle] infoDictionary] valueForKey:(NSString *)kCFBundleNameKey]; 80 | if (defaultName == nil) 81 | { 82 | defaultName = kMagicalRecordDefaultStoreFileName; 83 | } 84 | if (![defaultName hasSuffix:@"sqlite"]) 85 | { 86 | defaultName = [defaultName stringByAppendingPathExtension:@"sqlite"]; 87 | } 88 | 89 | return defaultName; 90 | } 91 | 92 | @end 93 | -------------------------------------------------------------------------------- /MagicalRecord/Core/MagicalRecordLogging.h: -------------------------------------------------------------------------------- 1 | // 2 | // MagicalRecordLogging.h 3 | // MagicalRecord 4 | // 5 | // Created by Saul Mora on 10/4/13. 6 | // Copyright (c) 2013 Magical Panda Software LLC. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #if MR_LOGGING_DISABLED 12 | 13 | #define MRLogError(frmt, ...) ((void)0) 14 | #define MRLogWarn(frmt, ...) ((void)0) 15 | #define MRLogInfo(frmt, ...) ((void)0) 16 | #define MRLogDebug(frmt, ...) ((void)0) 17 | #define MRLogVerbose(frmt, ...) ((void)0) 18 | 19 | #else 20 | 21 | #ifndef MR_LOGGING_CONTEXT 22 | #define MR_LOGGING_CONTEXT 0 23 | #endif 24 | 25 | #if __has_include("CocoaLumberjack.h") || __has_include("CocoaLumberjack/CocoaLumberjack.h") 26 | #define MR_LOG_LEVEL_DEF (DDLogLevel)[MagicalRecord loggingLevel] 27 | #define CAST (DDLogFlag) 28 | #import 29 | #else 30 | #define MR_LOG_LEVEL_DEF [MagicalRecord loggingLevel] 31 | #define LOG_ASYNC_ENABLED YES 32 | #define CAST 33 | #define LOG_MAYBE(async, lvl, flg, ctx, tag, fnct, frmt, ...) \ 34 | do \ 35 | { \ 36 | if ((lvl & flg) == flg) \ 37 | { \ 38 | NSLog(frmt, ##__VA_ARGS__); \ 39 | } \ 40 | } while (0) 41 | #endif 42 | 43 | #define MRLogError(frmt, ...) LOG_MAYBE(NO, MR_LOG_LEVEL_DEF, CAST MagicalRecordLoggingMaskError, MR_LOGGING_CONTEXT, nil, __PRETTY_FUNCTION__, frmt, ##__VA_ARGS__) 44 | #define MRLogWarn(frmt, ...) LOG_MAYBE(LOG_ASYNC_ENABLED, MR_LOG_LEVEL_DEF, CAST MagicalRecordLoggingMaskWarn, MR_LOGGING_CONTEXT, nil, __PRETTY_FUNCTION__, frmt, ##__VA_ARGS__) 45 | #define MRLogInfo(frmt, ...) LOG_MAYBE(LOG_ASYNC_ENABLED, MR_LOG_LEVEL_DEF, CAST MagicalRecordLoggingMaskInfo, MR_LOGGING_CONTEXT, nil, __PRETTY_FUNCTION__, frmt, ##__VA_ARGS__) 46 | #define MRLogDebug(frmt, ...) LOG_MAYBE(LOG_ASYNC_ENABLED, MR_LOG_LEVEL_DEF, CAST MagicalRecordLoggingMaskDebug, MR_LOGGING_CONTEXT, nil, __PRETTY_FUNCTION__, frmt, ##__VA_ARGS__) 47 | #define MRLogVerbose(frmt, ...) LOG_MAYBE(LOG_ASYNC_ENABLED, MR_LOG_LEVEL_DEF, CAST MagicalRecordLoggingMaskVerbose, MR_LOGGING_CONTEXT, nil, __PRETTY_FUNCTION__, frmt, ##__VA_ARGS__) 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /MagicalRecord/Core/MagicalRecordXcode7CompatibilityMacros.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright © 2015 Magical Panda Software LLC. All rights reserved. 3 | // 4 | // The following preprocessor macros can be used to adopt the new nullability annotations and generics 5 | // features available in Xcode 7, while maintaining backwards compatibility with earlier versions of 6 | // Xcode that do not support these features. 7 | // 8 | // Originally taken from https://gist.github.com/smileyborg/d513754bc1cf41678054 9 | 10 | #ifndef MagicalRecordXcode7CompatibilityMacros_h 11 | #define MagicalRecordXcode7CompatibilityMacros_h 12 | 13 | #if __has_feature(nullability) 14 | #define MR_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN 15 | #define MR_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END 16 | #define MR_nullable nullable 17 | #define MR_nonnull nonnull 18 | #define __MR_nullable __nullable 19 | #define __MR_nonnull __nonnull 20 | #else 21 | #define MR_ASSUME_NONNULL_BEGIN 22 | #define MR_ASSUME_NONNULL_END 23 | #define MR_nullable 24 | #define MR_nonnull 25 | #define __MR_nullable 26 | #define __MR_nonnull 27 | #endif 28 | 29 | #if __has_feature(objc_generics) 30 | #define MR_GENERIC(class, ...) class<__VA_ARGS__> 31 | #define MR_GENERIC_TYPE(type) type 32 | #define __MR_kindof(class) __kindof class 33 | #else 34 | #define MR_GENERIC(class, ...) class 35 | #define MR_GENERIC_TYPE(type) id 36 | #define __MR_kindof(class) id 37 | #endif 38 | 39 | #define MR_NSArrayOfNSManagedObjects MR_GENERIC(NSArray, __MR_kindof(NSManagedObject) *) * 40 | 41 | #endif /* MagicalRecordXcode7CompatibilityMacros_h */ 42 | -------------------------------------------------------------------------------- /MagicalRecord/MagicalRecord.h: -------------------------------------------------------------------------------- 1 | // 2 | // MagicalRecord.h 3 | // 4 | // Created by Saul Mora on 28/07/10. 5 | // Copyright 2010 Magical Panda Software, LLC All rights reserved. 6 | // 7 | 8 | #import 9 | #import 10 | 11 | //! Project version number for MagicalRecord. 12 | FOUNDATION_EXPORT double MagicalRecordVersionNumber; 13 | 14 | //! Project version string for MagicalRecord. 15 | FOUNDATION_EXPORT const unsigned char MagicalRecordVersionString[]; 16 | 17 | #import 18 | #import 19 | #import 20 | 21 | #import 22 | #import 23 | #import 24 | #import 25 | #import 26 | 27 | #import 28 | #import 29 | #import 30 | #import 31 | #import 32 | #import 33 | #import 34 | #import 35 | #import 36 | #import 37 | #import 38 | #import 39 | 40 | #import 41 | #import 42 | #import 43 | #import 44 | #import 45 | #import 46 | #import 47 | #import 48 | -------------------------------------------------------------------------------- /Samples/iOS/Application/Categories/ImageToDataTransformer.h: -------------------------------------------------------------------------------- 1 | // 2 | // ImageToDataTransformer.h 3 | // MagicalRecordRecipes 4 | // 5 | // Created by Saul Mora on 5/19/13. 6 | // 7 | // 8 | 9 | #import 10 | 11 | @interface ImageToDataTransformer : NSValueTransformer 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /Samples/iOS/Application/Categories/ImageToDataTransformer.m: -------------------------------------------------------------------------------- 1 | // 2 | // ImageToDataTransformer.m 3 | // MagicalRecordRecipes 4 | // 5 | // Created by Saul Mora on 5/19/13. 6 | // 7 | // 8 | 9 | #import "ImageToDataTransformer.h" 10 | 11 | 12 | @implementation ImageToDataTransformer 13 | 14 | 15 | + (BOOL)allowsReverseTransformation { 16 | return YES; 17 | } 18 | 19 | + (Class)transformedValueClass { 20 | return [NSData class]; 21 | } 22 | 23 | 24 | - (id)transformedValue:(id)value { 25 | NSData *data = UIImagePNGRepresentation(value); 26 | return data; 27 | } 28 | 29 | 30 | - (id)reverseTransformedValue:(id)value { 31 | UIImage *uiImage = [[UIImage alloc] initWithData:value]; 32 | return uiImage; 33 | } 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /Samples/iOS/Application/Controllers/AddressBook_Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'AddressBook' target in the 'AddressBook' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #import 8 | #endif 9 | 10 | #ifndef __ADDRESS_BOOK_FOR_IPHONE__ 11 | #define __ADDRESS_BOOK_FOR_IPHONE__ 1 12 | #endif -------------------------------------------------------------------------------- /Samples/iOS/Application/Controllers/EditingTableViewCell.h: -------------------------------------------------------------------------------- 1 | /* 2 | File: EditingTableViewCell.h 3 | Abstract: A table view cell that displays a label and a text field so that a value can be edited. The user interface is loaded from a nib file. 4 | 5 | Version: 1.4 6 | 7 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 8 | Inc. ("Apple") in consideration of your agreement to the following 9 | terms, and your use, installation, modification or redistribution of 10 | this Apple software constitutes acceptance of these terms. If you do 11 | not agree with these terms, please do not use, install, modify or 12 | redistribute this Apple software. 13 | 14 | In consideration of your agreement to abide by the following terms, and 15 | subject to these terms, Apple grants you a personal, non-exclusive 16 | license, under Apple's copyrights in this original Apple software (the 17 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 18 | Software, with or without modifications, in source and/or binary forms; 19 | provided that if you redistribute the Apple Software in its entirety and 20 | without modifications, you must retain this notice and the following 21 | text and disclaimers in all such redistributions of the Apple Software. 22 | Neither the name, trademarks, service marks or logos of Apple Inc. may 23 | be used to endorse or promote products derived from the Apple Software 24 | without specific prior written permission from Apple. Except as 25 | expressly stated in this notice, no other rights or licenses, express or 26 | implied, are granted by Apple herein, including but not limited to any 27 | patent rights that may be infringed by your derivative works or by other 28 | works in which the Apple Software may be incorporated. 29 | 30 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 31 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 32 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 33 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 34 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 35 | 36 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 37 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 38 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 39 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 40 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 41 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 42 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 43 | POSSIBILITY OF SUCH DAMAGE. 44 | 45 | Copyright (C) 2010 Apple Inc. All Rights Reserved. 46 | 47 | */ 48 | 49 | @interface EditingTableViewCell : UITableViewCell 50 | 51 | @property (nonatomic, retain) IBOutlet UILabel *label; 52 | @property (nonatomic, retain) IBOutlet UITextField *textField; 53 | 54 | @end 55 | -------------------------------------------------------------------------------- /Samples/iOS/Application/Controllers/EditingTableViewCell.m: -------------------------------------------------------------------------------- 1 | /* 2 | File: EditingTableViewCell.m 3 | Abstract: A table view cell that displays a label and a text field so that a value can be edited. The user interface is loaded from a nib file. 4 | 5 | Version: 1.4 6 | 7 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 8 | Inc. ("Apple") in consideration of your agreement to the following 9 | terms, and your use, installation, modification or redistribution of 10 | this Apple software constitutes acceptance of these terms. If you do 11 | not agree with these terms, please do not use, install, modify or 12 | redistribute this Apple software. 13 | 14 | In consideration of your agreement to abide by the following terms, and 15 | subject to these terms, Apple grants you a personal, non-exclusive 16 | license, under Apple's copyrights in this original Apple software (the 17 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 18 | Software, with or without modifications, in source and/or binary forms; 19 | provided that if you redistribute the Apple Software in its entirety and 20 | without modifications, you must retain this notice and the following 21 | text and disclaimers in all such redistributions of the Apple Software. 22 | Neither the name, trademarks, service marks or logos of Apple Inc. may 23 | be used to endorse or promote products derived from the Apple Software 24 | without specific prior written permission from Apple. Except as 25 | expressly stated in this notice, no other rights or licenses, express or 26 | implied, are granted by Apple herein, including but not limited to any 27 | patent rights that may be infringed by your derivative works or by other 28 | works in which the Apple Software may be incorporated. 29 | 30 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 31 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 32 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 33 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 34 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 35 | 36 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 37 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 38 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 39 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 40 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 41 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 42 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 43 | POSSIBILITY OF SUCH DAMAGE. 44 | 45 | Copyright (C) 2010 Apple Inc. All Rights Reserved. 46 | 47 | */ 48 | 49 | #import "EditingTableViewCell.h" 50 | 51 | @implementation EditingTableViewCell 52 | 53 | 54 | @end 55 | -------------------------------------------------------------------------------- /Samples/iOS/Application/Controllers/ImperialPickerController.h: -------------------------------------------------------------------------------- 1 | /* 2 | File: ImperialPickerController.h 3 | Abstract: Controller to managed a picker view displaying imperial weights. 4 | 5 | Version: 1.4 6 | 7 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 8 | Inc. ("Apple") in consideration of your agreement to the following 9 | terms, and your use, installation, modification or redistribution of 10 | this Apple software constitutes acceptance of these terms. If you do 11 | not agree with these terms, please do not use, install, modify or 12 | redistribute this Apple software. 13 | 14 | In consideration of your agreement to abide by the following terms, and 15 | subject to these terms, Apple grants you a personal, non-exclusive 16 | license, under Apple's copyrights in this original Apple software (the 17 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 18 | Software, with or without modifications, in source and/or binary forms; 19 | provided that if you redistribute the Apple Software in its entirety and 20 | without modifications, you must retain this notice and the following 21 | text and disclaimers in all such redistributions of the Apple Software. 22 | Neither the name, trademarks, service marks or logos of Apple Inc. may 23 | be used to endorse or promote products derived from the Apple Software 24 | without specific prior written permission from Apple. Except as 25 | expressly stated in this notice, no other rights or licenses, express or 26 | implied, are granted by Apple herein, including but not limited to any 27 | patent rights that may be infringed by your derivative works or by other 28 | works in which the Apple Software may be incorporated. 29 | 30 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 31 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 32 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 33 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 34 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 35 | 36 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 37 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 38 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 39 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 40 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 41 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 42 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 43 | POSSIBILITY OF SUCH DAMAGE. 44 | 45 | Copyright (C) 2010 Apple Inc. All Rights Reserved. 46 | 47 | */ 48 | 49 | @interface ImperialPickerController : NSObject 50 | 51 | @property (nonatomic, retain) IBOutlet UIPickerView *pickerView; 52 | @property (nonatomic, retain) IBOutlet UILabel *label; 53 | 54 | - (void)updateLabel; 55 | 56 | @end 57 | -------------------------------------------------------------------------------- /Samples/iOS/Application/Controllers/IngredientDetailViewController.h: -------------------------------------------------------------------------------- 1 | /* 2 | File: IngredientDetailViewController.h 3 | Abstract: Table view controller to manage editing details of a recipe ingredient -- its name and amount. 4 | 5 | Version: 1.4 6 | 7 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 8 | Inc. ("Apple") in consideration of your agreement to the following 9 | terms, and your use, installation, modification or redistribution of 10 | this Apple software constitutes acceptance of these terms. If you do 11 | not agree with these terms, please do not use, install, modify or 12 | redistribute this Apple software. 13 | 14 | In consideration of your agreement to abide by the following terms, and 15 | subject to these terms, Apple grants you a personal, non-exclusive 16 | license, under Apple's copyrights in this original Apple software (the 17 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 18 | Software, with or without modifications, in source and/or binary forms; 19 | provided that if you redistribute the Apple Software in its entirety and 20 | without modifications, you must retain this notice and the following 21 | text and disclaimers in all such redistributions of the Apple Software. 22 | Neither the name, trademarks, service marks or logos of Apple Inc. may 23 | be used to endorse or promote products derived from the Apple Software 24 | without specific prior written permission from Apple. Except as 25 | expressly stated in this notice, no other rights or licenses, express or 26 | implied, are granted by Apple herein, including but not limited to any 27 | patent rights that may be infringed by your derivative works or by other 28 | works in which the Apple Software may be incorporated. 29 | 30 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 31 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 32 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 33 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 34 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 35 | 36 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 37 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 38 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 39 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 40 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 41 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 42 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 43 | POSSIBILITY OF SUCH DAMAGE. 44 | 45 | Copyright (C) 2010 Apple Inc. All Rights Reserved. 46 | 47 | */ 48 | 49 | @class Recipe, Ingredient, EditingTableViewCell; 50 | 51 | @interface IngredientDetailViewController : UITableViewController 52 | 53 | @property (nonatomic, retain) Recipe *recipe; 54 | @property (nonatomic, retain) Ingredient *ingredient; 55 | 56 | @property (nonatomic, weak) IBOutlet EditingTableViewCell *editingTableViewCell; 57 | 58 | @end 59 | -------------------------------------------------------------------------------- /Samples/iOS/Application/Controllers/InstructionsViewController.h: -------------------------------------------------------------------------------- 1 | /* 2 | File: InstructionsViewController.h 3 | Abstract: View controller to manage a text view to allow the user to edit instructions for a recipe. 4 | 5 | Version: 1.4 6 | 7 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 8 | Inc. ("Apple") in consideration of your agreement to the following 9 | terms, and your use, installation, modification or redistribution of 10 | this Apple software constitutes acceptance of these terms. If you do 11 | not agree with these terms, please do not use, install, modify or 12 | redistribute this Apple software. 13 | 14 | In consideration of your agreement to abide by the following terms, and 15 | subject to these terms, Apple grants you a personal, non-exclusive 16 | license, under Apple's copyrights in this original Apple software (the 17 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 18 | Software, with or without modifications, in source and/or binary forms; 19 | provided that if you redistribute the Apple Software in its entirety and 20 | without modifications, you must retain this notice and the following 21 | text and disclaimers in all such redistributions of the Apple Software. 22 | Neither the name, trademarks, service marks or logos of Apple Inc. may 23 | be used to endorse or promote products derived from the Apple Software 24 | without specific prior written permission from Apple. Except as 25 | expressly stated in this notice, no other rights or licenses, express or 26 | implied, are granted by Apple herein, including but not limited to any 27 | patent rights that may be infringed by your derivative works or by other 28 | works in which the Apple Software may be incorporated. 29 | 30 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 31 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 32 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 33 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 34 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 35 | 36 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 37 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 38 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 39 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 40 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 41 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 42 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 43 | POSSIBILITY OF SUCH DAMAGE. 44 | 45 | Copyright (C) 2010 Apple Inc. All Rights Reserved. 46 | 47 | */ 48 | 49 | @class Recipe; 50 | 51 | @interface InstructionsViewController : UIViewController 52 | 53 | @property (nonatomic, retain) Recipe *recipe; 54 | @property (nonatomic, retain) IBOutlet UITextView *instructionsText; 55 | @property (nonatomic, retain) IBOutlet UILabel *nameLabel; 56 | 57 | @end 58 | -------------------------------------------------------------------------------- /Samples/iOS/Application/Controllers/MetricPickerController.h: -------------------------------------------------------------------------------- 1 | /* 2 | File: MetricPickerController.h 3 | Abstract: Controller to managed a picker view displaying metric weights. 4 | 5 | Version: 1.4 6 | 7 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 8 | Inc. ("Apple") in consideration of your agreement to the following 9 | terms, and your use, installation, modification or redistribution of 10 | this Apple software constitutes acceptance of these terms. If you do 11 | not agree with these terms, please do not use, install, modify or 12 | redistribute this Apple software. 13 | 14 | In consideration of your agreement to abide by the following terms, and 15 | subject to these terms, Apple grants you a personal, non-exclusive 16 | license, under Apple's copyrights in this original Apple software (the 17 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 18 | Software, with or without modifications, in source and/or binary forms; 19 | provided that if you redistribute the Apple Software in its entirety and 20 | without modifications, you must retain this notice and the following 21 | text and disclaimers in all such redistributions of the Apple Software. 22 | Neither the name, trademarks, service marks or logos of Apple Inc. may 23 | be used to endorse or promote products derived from the Apple Software 24 | without specific prior written permission from Apple. Except as 25 | expressly stated in this notice, no other rights or licenses, express or 26 | implied, are granted by Apple herein, including but not limited to any 27 | patent rights that may be infringed by your derivative works or by other 28 | works in which the Apple Software may be incorporated. 29 | 30 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 31 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 32 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 33 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 34 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 35 | 36 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 37 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 38 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 39 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 40 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 41 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 42 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 43 | POSSIBILITY OF SUCH DAMAGE. 44 | 45 | Copyright (C) 2010 Apple Inc. All Rights Reserved. 46 | 47 | */ 48 | 49 | @interface MetricPickerController : NSObject 50 | 51 | @property (nonatomic, retain) IBOutlet UIPickerView *pickerView; 52 | @property (nonatomic, retain) IBOutlet UILabel *label; 53 | 54 | - (UIView *)viewForComponent:(NSInteger)component; 55 | - (void)updateLabel; 56 | 57 | @end 58 | -------------------------------------------------------------------------------- /Samples/iOS/Application/Controllers/RecipePhotoViewController.h: -------------------------------------------------------------------------------- 1 | /* 2 | File: RecipePhotoViewController.h 3 | Abstract: View controller to manage a view to display a recipe's photo. 4 | The image view is created programmatically. 5 | 6 | Version: 1.4 7 | 8 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 9 | Inc. ("Apple") in consideration of your agreement to the following 10 | terms, and your use, installation, modification or redistribution of 11 | this Apple software constitutes acceptance of these terms. If you do 12 | not agree with these terms, please do not use, install, modify or 13 | redistribute this Apple software. 14 | 15 | In consideration of your agreement to abide by the following terms, and 16 | subject to these terms, Apple grants you a personal, non-exclusive 17 | license, under Apple's copyrights in this original Apple software (the 18 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 19 | Software, with or without modifications, in source and/or binary forms; 20 | provided that if you redistribute the Apple Software in its entirety and 21 | without modifications, you must retain this notice and the following 22 | text and disclaimers in all such redistributions of the Apple Software. 23 | Neither the name, trademarks, service marks or logos of Apple Inc. may 24 | be used to endorse or promote products derived from the Apple Software 25 | without specific prior written permission from Apple. Except as 26 | expressly stated in this notice, no other rights or licenses, express or 27 | implied, are granted by Apple herein, including but not limited to any 28 | patent rights that may be infringed by your derivative works or by other 29 | works in which the Apple Software may be incorporated. 30 | 31 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 32 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 33 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 34 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 35 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 36 | 37 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 38 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 39 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 40 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 41 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 42 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 43 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 44 | POSSIBILITY OF SUCH DAMAGE. 45 | 46 | Copyright (C) 2010 Apple Inc. All Rights Reserved. 47 | 48 | */ 49 | 50 | @class Recipe; 51 | 52 | @interface RecipePhotoViewController : UIViewController 53 | 54 | @property(nonatomic, retain) Recipe *recipe; 55 | @property(nonatomic, retain) UIImageView *imageView; 56 | 57 | @end 58 | -------------------------------------------------------------------------------- /Samples/iOS/Application/Controllers/TemperatureCell.h: -------------------------------------------------------------------------------- 1 | /* 2 | File: TemperatureCell.h 3 | Abstract: A table view cell that displays temperature in Centigrade, Fahrenheit, and Gas Mark. 4 | 5 | Version: 1.4 6 | 7 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 8 | Inc. ("Apple") in consideration of your agreement to the following 9 | terms, and your use, installation, modification or redistribution of 10 | this Apple software constitutes acceptance of these terms. If you do 11 | not agree with these terms, please do not use, install, modify or 12 | redistribute this Apple software. 13 | 14 | In consideration of your agreement to abide by the following terms, and 15 | subject to these terms, Apple grants you a personal, non-exclusive 16 | license, under Apple's copyrights in this original Apple software (the 17 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 18 | Software, with or without modifications, in source and/or binary forms; 19 | provided that if you redistribute the Apple Software in its entirety and 20 | without modifications, you must retain this notice and the following 21 | text and disclaimers in all such redistributions of the Apple Software. 22 | Neither the name, trademarks, service marks or logos of Apple Inc. may 23 | be used to endorse or promote products derived from the Apple Software 24 | without specific prior written permission from Apple. Except as 25 | expressly stated in this notice, no other rights or licenses, express or 26 | implied, are granted by Apple herein, including but not limited to any 27 | patent rights that may be infringed by your derivative works or by other 28 | works in which the Apple Software may be incorporated. 29 | 30 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 31 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 32 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 33 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 34 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 35 | 36 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 37 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 38 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 39 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 40 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 41 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 42 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 43 | POSSIBILITY OF SUCH DAMAGE. 44 | 45 | Copyright (C) 2010 Apple Inc. All Rights Reserved. 46 | 47 | */ 48 | 49 | @interface TemperatureCell : UITableViewCell { 50 | 51 | UILabel *cLabel; 52 | UILabel *fLabel; 53 | UILabel *gLabel; 54 | } 55 | 56 | @property (nonatomic, retain) IBOutlet UILabel *cLabel; 57 | @property (nonatomic, retain) IBOutlet UILabel *fLabel; 58 | @property (nonatomic, retain) IBOutlet UILabel *gLabel; 59 | 60 | - (void)setTemperatureDataFromDictionary:(NSDictionary *)temperatureDictionary; 61 | 62 | @end 63 | -------------------------------------------------------------------------------- /Samples/iOS/Application/Controllers/TemperatureCell.m: -------------------------------------------------------------------------------- 1 | /* 2 | File: TemperatureCell.m 3 | Abstract: A table view cell that displays temperature in Centigrade, Fahrenheit, and Gas Mark. 4 | 5 | Version: 1.4 6 | 7 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 8 | Inc. ("Apple") in consideration of your agreement to the following 9 | terms, and your use, installation, modification or redistribution of 10 | this Apple software constitutes acceptance of these terms. If you do 11 | not agree with these terms, please do not use, install, modify or 12 | redistribute this Apple software. 13 | 14 | In consideration of your agreement to abide by the following terms, and 15 | subject to these terms, Apple grants you a personal, non-exclusive 16 | license, under Apple's copyrights in this original Apple software (the 17 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 18 | Software, with or without modifications, in source and/or binary forms; 19 | provided that if you redistribute the Apple Software in its entirety and 20 | without modifications, you must retain this notice and the following 21 | text and disclaimers in all such redistributions of the Apple Software. 22 | Neither the name, trademarks, service marks or logos of Apple Inc. may 23 | be used to endorse or promote products derived from the Apple Software 24 | without specific prior written permission from Apple. Except as 25 | expressly stated in this notice, no other rights or licenses, express or 26 | implied, are granted by Apple herein, including but not limited to any 27 | patent rights that may be infringed by your derivative works or by other 28 | works in which the Apple Software may be incorporated. 29 | 30 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 31 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 32 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 33 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 34 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 35 | 36 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 37 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 38 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 39 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 40 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 41 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 42 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 43 | POSSIBILITY OF SUCH DAMAGE. 44 | 45 | Copyright (C) 2010 Apple Inc. All Rights Reserved. 46 | 47 | */ 48 | 49 | #import "TemperatureCell.h" 50 | 51 | 52 | @implementation TemperatureCell 53 | 54 | @synthesize cLabel, fLabel, gLabel; 55 | 56 | 57 | - (void)setTemperatureDataFromDictionary:(NSDictionary *)temperatureDictionary { 58 | // Update text in labels from the dictionary 59 | cLabel.text = temperatureDictionary[@"c"]; 60 | fLabel.text = temperatureDictionary[@"f"]; 61 | gLabel.text = temperatureDictionary[@"g"]; 62 | } 63 | 64 | 65 | 66 | 67 | @end 68 | -------------------------------------------------------------------------------- /Samples/iOS/Application/Controllers/TemperatureConverterViewController.h: -------------------------------------------------------------------------------- 1 | /* 2 | File: TemperatureConverterViewController.h 3 | Abstract: View controller to display cooking temperatures in Centigrade, Fahrenheit, and Gas Mark. 4 | 5 | Version: 1.4 6 | 7 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 8 | Inc. ("Apple") in consideration of your agreement to the following 9 | terms, and your use, installation, modification or redistribution of 10 | this Apple software constitutes acceptance of these terms. If you do 11 | not agree with these terms, please do not use, install, modify or 12 | redistribute this Apple software. 13 | 14 | In consideration of your agreement to abide by the following terms, and 15 | subject to these terms, Apple grants you a personal, non-exclusive 16 | license, under Apple's copyrights in this original Apple software (the 17 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 18 | Software, with or without modifications, in source and/or binary forms; 19 | provided that if you redistribute the Apple Software in its entirety and 20 | without modifications, you must retain this notice and the following 21 | text and disclaimers in all such redistributions of the Apple Software. 22 | Neither the name, trademarks, service marks or logos of Apple Inc. may 23 | be used to endorse or promote products derived from the Apple Software 24 | without specific prior written permission from Apple. Except as 25 | expressly stated in this notice, no other rights or licenses, express or 26 | implied, are granted by Apple herein, including but not limited to any 27 | patent rights that may be infringed by your derivative works or by other 28 | works in which the Apple Software may be incorporated. 29 | 30 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 31 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 32 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 33 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 34 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 35 | 36 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 37 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 38 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 39 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 40 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 41 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 42 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 43 | POSSIBILITY OF SUCH DAMAGE. 44 | 45 | Copyright (C) 2010 Apple Inc. All Rights Reserved. 46 | 47 | */ 48 | 49 | @class TemperatureCell; 50 | 51 | @interface TemperatureConverterViewController : UIViewController 52 | 53 | @property (nonatomic, retain) NSArray *temperatureData; 54 | 55 | @property (nonatomic, retain) IBOutlet UITableView *tableView; 56 | @property (nonatomic, retain) IBOutlet TemperatureCell *temperatureCell; 57 | 58 | @end 59 | -------------------------------------------------------------------------------- /Samples/iOS/Application/Controllers/TypeSelectionViewController.h: -------------------------------------------------------------------------------- 1 | /* 2 | File: TypeSelectionViewController.h 3 | Abstract: Table view controller to allow the user to select the recipe type. 4 | The options are presented as items in the table view; the selected item has a check mark in the accessory view. The controller caches the index path of the selected item to avoid the need to perform repeated string comparisons after an update. 5 | 6 | Version: 1.4 7 | 8 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 9 | Inc. ("Apple") in consideration of your agreement to the following 10 | terms, and your use, installation, modification or redistribution of 11 | this Apple software constitutes acceptance of these terms. If you do 12 | not agree with these terms, please do not use, install, modify or 13 | redistribute this Apple software. 14 | 15 | In consideration of your agreement to abide by the following terms, and 16 | subject to these terms, Apple grants you a personal, non-exclusive 17 | license, under Apple's copyrights in this original Apple software (the 18 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 19 | Software, with or without modifications, in source and/or binary forms; 20 | provided that if you redistribute the Apple Software in its entirety and 21 | without modifications, you must retain this notice and the following 22 | text and disclaimers in all such redistributions of the Apple Software. 23 | Neither the name, trademarks, service marks or logos of Apple Inc. may 24 | be used to endorse or promote products derived from the Apple Software 25 | without specific prior written permission from Apple. Except as 26 | expressly stated in this notice, no other rights or licenses, express or 27 | implied, are granted by Apple herein, including but not limited to any 28 | patent rights that may be infringed by your derivative works or by other 29 | works in which the Apple Software may be incorporated. 30 | 31 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 32 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 33 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 34 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 35 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 36 | 37 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 38 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 39 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 40 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 41 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 42 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 43 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 44 | POSSIBILITY OF SUCH DAMAGE. 45 | 46 | Copyright (C) 2010 Apple Inc. All Rights Reserved. 47 | 48 | */ 49 | 50 | @class Recipe; 51 | 52 | @interface TypeSelectionViewController : UITableViewController 53 | 54 | @property (nonatomic, retain) Recipe *recipe; 55 | @property (nonatomic, retain, readonly) NSArray *recipeTypes; 56 | 57 | @end 58 | -------------------------------------------------------------------------------- /Samples/iOS/Application/Controllers/UnitConverterTableViewController.h: -------------------------------------------------------------------------------- 1 | /* 2 | File: UnitConverterTableViewController.h 3 | Abstract: Table view controller to display two table view cells to allow the user to select a unit converter. 4 | 5 | 6 | Version: 1.4 7 | 8 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 9 | Inc. ("Apple") in consideration of your agreement to the following 10 | terms, and your use, installation, modification or redistribution of 11 | this Apple software constitutes acceptance of these terms. If you do 12 | not agree with these terms, please do not use, install, modify or 13 | redistribute this Apple software. 14 | 15 | In consideration of your agreement to abide by the following terms, and 16 | subject to these terms, Apple grants you a personal, non-exclusive 17 | license, under Apple's copyrights in this original Apple software (the 18 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 19 | Software, with or without modifications, in source and/or binary forms; 20 | provided that if you redistribute the Apple Software in its entirety and 21 | without modifications, you must retain this notice and the following 22 | text and disclaimers in all such redistributions of the Apple Software. 23 | Neither the name, trademarks, service marks or logos of Apple Inc. may 24 | be used to endorse or promote products derived from the Apple Software 25 | without specific prior written permission from Apple. Except as 26 | expressly stated in this notice, no other rights or licenses, express or 27 | implied, are granted by Apple herein, including but not limited to any 28 | patent rights that may be infringed by your derivative works or by other 29 | works in which the Apple Software may be incorporated. 30 | 31 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 32 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 33 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 34 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 35 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 36 | 37 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 38 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 39 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 40 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 41 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 42 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 43 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 44 | POSSIBILITY OF SUCH DAMAGE. 45 | 46 | Copyright (C) 2010 Apple Inc. All Rights Reserved. 47 | 48 | */ 49 | 50 | @interface UnitConverterTableViewController : UITableViewController 51 | 52 | @end 53 | -------------------------------------------------------------------------------- /Samples/iOS/Application/Delegate/MGPRecipesAppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // MGPAppDelegate.h 3 | // Recipes 4 | // 5 | // Created by Saul Mora on 5/19/13. 6 | // 7 | // 8 | 9 | #import 10 | #import "RecipeListTableViewController.h" 11 | 12 | @interface MGPRecipesAppDelegate : UIResponder 13 | 14 | @property (nonatomic, strong) IBOutlet UIWindow *window; 15 | @property (nonatomic, strong) IBOutlet UITabBarController *tabBarController; 16 | @property (nonatomic, strong) IBOutlet RecipeListTableViewController *recipeListController; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /Samples/iOS/Application/Delegate/MGPRecipesAppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // MGPAppDelegate.m 3 | // Recipes 4 | // 5 | // Created by Saul Mora on 5/19/13. 6 | // 7 | // 8 | 9 | #import "MGPRecipesAppDelegate.h" 10 | 11 | static NSString * const kRecipesStoreName = @"Recipes.sqlite"; 12 | 13 | @implementation MGPRecipesAppDelegate 14 | 15 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 16 | { 17 | [self copyDefaultStoreIfNecessary]; 18 | [MagicalRecord setLoggingLevel:MagicalRecordLoggingLevelVerbose]; 19 | [MagicalRecord setupCoreDataStackWithStoreNamed:kRecipesStoreName]; 20 | 21 | // Override point for customization after application launch. 22 | self.recipeListController.managedObjectContext = [NSManagedObjectContext MR_defaultContext]; 23 | [self.window setRootViewController:self.tabBarController]; 24 | [self.window makeKeyAndVisible]; 25 | return YES; 26 | } 27 | 28 | - (void) copyDefaultStoreIfNecessary; 29 | { 30 | NSFileManager *fileManager = [NSFileManager defaultManager]; 31 | 32 | NSURL *storeURL = [NSPersistentStore MR_urlForStoreName:kRecipesStoreName]; 33 | 34 | // If the expected store doesn't exist, copy the default store. 35 | if (![fileManager fileExistsAtPath:[storeURL path]]) 36 | { 37 | NSString *defaultStorePath = [[NSBundle mainBundle] pathForResource:[kRecipesStoreName stringByDeletingPathExtension] ofType:[kRecipesStoreName pathExtension]]; 38 | 39 | if (defaultStorePath) 40 | { 41 | NSError *error; 42 | BOOL success = [fileManager copyItemAtPath:defaultStorePath toPath:[storeURL path] error:&error]; 43 | if (!success) 44 | { 45 | NSLog(@"Failed to install default recipe store"); 46 | } 47 | } 48 | } 49 | 50 | } 51 | @end 52 | -------------------------------------------------------------------------------- /Samples/iOS/Application/Models/Recipes.xcdatamodeld/.xccurrentversion: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | _XCCurrentVersionName 6 | Recipes.xcdatamodel 7 | 8 | 9 | -------------------------------------------------------------------------------- /Samples/iOS/Application/Models/Recipes.xcdatamodeld/Recipes 2.xcdatamodel/elements: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/magicalpanda/MagicalRecord/6031f608b79c1d6802007aaed6efd100e11f59ba/Samples/iOS/Application/Models/Recipes.xcdatamodeld/Recipes 2.xcdatamodel/elements -------------------------------------------------------------------------------- /Samples/iOS/Application/Models/Recipes.xcdatamodeld/Recipes 2.xcdatamodel/layout: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/magicalpanda/MagicalRecord/6031f608b79c1d6802007aaed6efd100e11f59ba/Samples/iOS/Application/Models/Recipes.xcdatamodeld/Recipes 2.xcdatamodel/layout -------------------------------------------------------------------------------- /Samples/iOS/Application/Models/Recipes.xcdatamodeld/Recipes.xcdatamodel/elements: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/magicalpanda/MagicalRecord/6031f608b79c1d6802007aaed6efd100e11f59ba/Samples/iOS/Application/Models/Recipes.xcdatamodeld/Recipes.xcdatamodel/elements -------------------------------------------------------------------------------- /Samples/iOS/Application/Models/Recipes.xcdatamodeld/Recipes.xcdatamodel/layout: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/magicalpanda/MagicalRecord/6031f608b79c1d6802007aaed6efd100e11f59ba/Samples/iOS/Application/Models/Recipes.xcdatamodeld/Recipes.xcdatamodel/layout -------------------------------------------------------------------------------- /Samples/iOS/Application/Models/entities/Ingredient.h: -------------------------------------------------------------------------------- 1 | #import "_Ingredient.h" 2 | 3 | @interface Ingredient : _Ingredient {} 4 | // Custom logic goes here. 5 | @end 6 | -------------------------------------------------------------------------------- /Samples/iOS/Application/Models/entities/Ingredient.m: -------------------------------------------------------------------------------- 1 | #import "Ingredient.h" 2 | 3 | 4 | @interface Ingredient () 5 | 6 | // Private interface goes here. 7 | 8 | @end 9 | 10 | 11 | @implementation Ingredient 12 | 13 | // Custom logic goes here. 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /Samples/iOS/Application/Models/entities/Recipe.h: -------------------------------------------------------------------------------- 1 | #import "_Recipe.h" 2 | 3 | @interface Recipe : _Recipe {} 4 | // Custom logic goes here. 5 | @end 6 | -------------------------------------------------------------------------------- /Samples/iOS/Application/Models/entities/Recipe.m: -------------------------------------------------------------------------------- 1 | #import "Recipe.h" 2 | 3 | 4 | @interface Recipe () 5 | 6 | // Private interface goes here. 7 | 8 | @end 9 | 10 | 11 | @implementation Recipe 12 | 13 | // Custom logic goes here. 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /Samples/iOS/Application/Models/generated/_Ingredient.h: -------------------------------------------------------------------------------- 1 | // DO NOT EDIT. This file is machine-generated and constantly overwritten. 2 | // Make changes to Ingredient.h instead. 3 | 4 | #import 5 | 6 | 7 | extern const struct IngredientAttributes { 8 | __unsafe_unretained NSString *amount; 9 | __unsafe_unretained NSString *displayOrder; 10 | __unsafe_unretained NSString *name; 11 | } IngredientAttributes; 12 | 13 | extern const struct IngredientRelationships { 14 | __unsafe_unretained NSString *recipe; 15 | } IngredientRelationships; 16 | 17 | extern const struct IngredientFetchedProperties { 18 | } IngredientFetchedProperties; 19 | 20 | @class Recipe; 21 | 22 | 23 | 24 | 25 | 26 | @interface IngredientID : NSManagedObjectID {} 27 | @end 28 | 29 | @interface _Ingredient : NSManagedObject {} 30 | + (id)insertInManagedObjectContext:(NSManagedObjectContext*)moc_; 31 | + (NSString*)entityName; 32 | + (NSEntityDescription*)entityInManagedObjectContext:(NSManagedObjectContext*)moc_; 33 | - (IngredientID*)objectID; 34 | 35 | 36 | 37 | 38 | 39 | @property (nonatomic, strong) NSString* amount; 40 | 41 | 42 | 43 | //- (BOOL)validateAmount:(id*)value_ error:(NSError**)error_; 44 | 45 | 46 | 47 | 48 | 49 | @property (nonatomic, strong) NSNumber* displayOrder; 50 | 51 | 52 | 53 | @property int16_t displayOrderValue; 54 | - (int16_t)displayOrderValue; 55 | - (void)setDisplayOrderValue:(int16_t)value_; 56 | 57 | //- (BOOL)validateDisplayOrder:(id*)value_ error:(NSError**)error_; 58 | 59 | 60 | 61 | 62 | 63 | @property (nonatomic, strong) NSString* name; 64 | 65 | 66 | 67 | //- (BOOL)validateName:(id*)value_ error:(NSError**)error_; 68 | 69 | 70 | 71 | 72 | 73 | @property (nonatomic, strong) Recipe *recipe; 74 | 75 | //- (BOOL)validateRecipe:(id*)value_ error:(NSError**)error_; 76 | 77 | 78 | 79 | 80 | 81 | @end 82 | 83 | @interface _Ingredient (CoreDataGeneratedAccessors) 84 | 85 | @end 86 | 87 | @interface _Ingredient (CoreDataGeneratedPrimitiveAccessors) 88 | 89 | 90 | - (NSString*)primitiveAmount; 91 | - (void)setPrimitiveAmount:(NSString*)value; 92 | 93 | 94 | 95 | 96 | - (NSNumber*)primitiveDisplayOrder; 97 | - (void)setPrimitiveDisplayOrder:(NSNumber*)value; 98 | 99 | - (int16_t)primitiveDisplayOrderValue; 100 | - (void)setPrimitiveDisplayOrderValue:(int16_t)value_; 101 | 102 | 103 | 104 | 105 | - (NSString*)primitiveName; 106 | - (void)setPrimitiveName:(NSString*)value; 107 | 108 | 109 | 110 | 111 | 112 | - (Recipe*)primitiveRecipe; 113 | - (void)setPrimitiveRecipe:(Recipe*)value; 114 | 115 | 116 | @end 117 | -------------------------------------------------------------------------------- /Samples/iOS/Application/Models/generated/_Ingredient.m: -------------------------------------------------------------------------------- 1 | // DO NOT EDIT. This file is machine-generated and constantly overwritten. 2 | // Make changes to Ingredient.m instead. 3 | 4 | #import "_Ingredient.h" 5 | 6 | const struct IngredientAttributes IngredientAttributes = { 7 | .amount = @"amount", 8 | .displayOrder = @"displayOrder", 9 | .name = @"name", 10 | }; 11 | 12 | const struct IngredientRelationships IngredientRelationships = { 13 | .recipe = @"recipe", 14 | }; 15 | 16 | const struct IngredientFetchedProperties IngredientFetchedProperties = { 17 | }; 18 | 19 | @implementation IngredientID 20 | @end 21 | 22 | @implementation _Ingredient 23 | 24 | + (id)insertInManagedObjectContext:(NSManagedObjectContext*)moc_ { 25 | NSParameterAssert(moc_); 26 | return [NSEntityDescription insertNewObjectForEntityForName:@"Ingredient" inManagedObjectContext:moc_]; 27 | } 28 | 29 | + (NSString*)entityName { 30 | return @"Ingredient"; 31 | } 32 | 33 | + (NSEntityDescription*)entityInManagedObjectContext:(NSManagedObjectContext*)moc_ { 34 | NSParameterAssert(moc_); 35 | return [NSEntityDescription entityForName:@"Ingredient" inManagedObjectContext:moc_]; 36 | } 37 | 38 | - (IngredientID*)objectID { 39 | return (IngredientID*)[super objectID]; 40 | } 41 | 42 | + (NSSet*)keyPathsForValuesAffectingValueForKey:(NSString*)key { 43 | NSSet *keyPaths = [super keyPathsForValuesAffectingValueForKey:key]; 44 | 45 | if ([key isEqualToString:@"displayOrderValue"]) { 46 | NSSet *affectingKey = [NSSet setWithObject:@"displayOrder"]; 47 | keyPaths = [keyPaths setByAddingObjectsFromSet:affectingKey]; 48 | return keyPaths; 49 | } 50 | 51 | return keyPaths; 52 | } 53 | 54 | 55 | 56 | 57 | @dynamic amount; 58 | 59 | 60 | 61 | 62 | 63 | 64 | @dynamic displayOrder; 65 | 66 | 67 | 68 | - (int16_t)displayOrderValue { 69 | NSNumber *result = [self displayOrder]; 70 | return [result shortValue]; 71 | } 72 | 73 | - (void)setDisplayOrderValue:(int16_t)value_ { 74 | [self setDisplayOrder:@(value_)]; 75 | } 76 | 77 | - (int16_t)primitiveDisplayOrderValue { 78 | NSNumber *result = [self primitiveDisplayOrder]; 79 | return [result shortValue]; 80 | } 81 | 82 | - (void)setPrimitiveDisplayOrderValue:(int16_t)value_ { 83 | [self setPrimitiveDisplayOrder:@(value_)]; 84 | } 85 | 86 | 87 | 88 | 89 | 90 | @dynamic name; 91 | 92 | 93 | 94 | 95 | 96 | 97 | @dynamic recipe; 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | @end 107 | -------------------------------------------------------------------------------- /Samples/iOS/Application/Models/generated/_Recipe.m: -------------------------------------------------------------------------------- 1 | // DO NOT EDIT. This file is machine-generated and constantly overwritten. 2 | // Make changes to Recipe.m instead. 3 | 4 | #import "_Recipe.h" 5 | 6 | const struct RecipeAttributes RecipeAttributes = { 7 | .instructions = @"instructions", 8 | .name = @"name", 9 | .overview = @"overview", 10 | .prepTime = @"prepTime", 11 | .thumbnailImage = @"thumbnailImage", 12 | }; 13 | 14 | const struct RecipeRelationships RecipeRelationships = { 15 | .image = @"image", 16 | .ingredients = @"ingredients", 17 | .type = @"type", 18 | }; 19 | 20 | const struct RecipeFetchedProperties RecipeFetchedProperties = { 21 | }; 22 | 23 | @implementation RecipeID 24 | @end 25 | 26 | @implementation _Recipe 27 | 28 | + (id)insertInManagedObjectContext:(NSManagedObjectContext*)moc_ { 29 | NSParameterAssert(moc_); 30 | return [NSEntityDescription insertNewObjectForEntityForName:@"Recipe" inManagedObjectContext:moc_]; 31 | } 32 | 33 | + (NSString*)entityName { 34 | return @"Recipe"; 35 | } 36 | 37 | + (NSEntityDescription*)entityInManagedObjectContext:(NSManagedObjectContext*)moc_ { 38 | NSParameterAssert(moc_); 39 | return [NSEntityDescription entityForName:@"Recipe" inManagedObjectContext:moc_]; 40 | } 41 | 42 | - (RecipeID*)objectID { 43 | return (RecipeID*)[super objectID]; 44 | } 45 | 46 | + (NSSet*)keyPathsForValuesAffectingValueForKey:(NSString*)key { 47 | NSSet *keyPaths = [super keyPathsForValuesAffectingValueForKey:key]; 48 | 49 | 50 | return keyPaths; 51 | } 52 | 53 | 54 | 55 | 56 | @dynamic instructions; 57 | 58 | 59 | 60 | 61 | 62 | 63 | @dynamic name; 64 | 65 | 66 | 67 | 68 | 69 | 70 | @dynamic overview; 71 | 72 | 73 | 74 | 75 | 76 | 77 | @dynamic prepTime; 78 | 79 | 80 | 81 | 82 | 83 | 84 | @dynamic thumbnailImage; 85 | 86 | 87 | 88 | 89 | 90 | 91 | @dynamic image; 92 | 93 | 94 | 95 | @dynamic ingredients; 96 | 97 | 98 | - (NSMutableSet*)ingredientsSet { 99 | [self willAccessValueForKey:@"ingredients"]; 100 | 101 | NSMutableSet *result = (NSMutableSet*)[self mutableSetValueForKey:@"ingredients"]; 102 | 103 | [self didAccessValueForKey:@"ingredients"]; 104 | return result; 105 | } 106 | 107 | 108 | @dynamic type; 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | @end 118 | -------------------------------------------------------------------------------- /Samples/iOS/Application/Support/Recipes-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIdentifier 12 | com.magicalpanda.samples.${PRODUCT_NAME:rfc1034identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1 25 | LSRequiresIPhoneOS 26 | 27 | NSMainNibFile 28 | MainWindow 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /Samples/iOS/Application/Support/Recipes-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'Recipes' target in the 'Recipes' project 3 | // 4 | 5 | #import 6 | 7 | #ifndef __IPHONE_3_0 8 | #warning "This project uses features only available in iOS SDK 3.0 and later." 9 | #endif 10 | 11 | #ifdef __OBJC__ 12 | #import 13 | #import 14 | #import "MagicalRecord.h" 15 | #endif 16 | -------------------------------------------------------------------------------- /Samples/iOS/Application/Support/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /Samples/iOS/Application/Support/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // Recipes 4 | // 5 | // Created by Saul Mora on 5/19/13. 6 | // 7 | // 8 | 9 | #import 10 | 11 | #import "MGPRecipesAppDelegate.h" 12 | 13 | int main(int argc, char *argv[]) 14 | { 15 | @autoreleasepool { 16 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([MGPRecipesAppDelegate class])); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Samples/iOS/Application/Views/RecipeAddView.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /Samples/iOS/Resources/Default-568h@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/magicalpanda/MagicalRecord/6031f608b79c1d6802007aaed6efd100e11f59ba/Samples/iOS/Resources/Default-568h@2x.png -------------------------------------------------------------------------------- /Samples/iOS/Resources/Default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/magicalpanda/MagicalRecord/6031f608b79c1d6802007aaed6efd100e11f59ba/Samples/iOS/Resources/Default.png -------------------------------------------------------------------------------- /Samples/iOS/Resources/Default@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/magicalpanda/MagicalRecord/6031f608b79c1d6802007aaed6efd100e11f59ba/Samples/iOS/Resources/Default@2x.png -------------------------------------------------------------------------------- /Samples/iOS/Resources/RecipeData/Recipes.sqlite: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/magicalpanda/MagicalRecord/6031f608b79c1d6802007aaed6efd100e11f59ba/Samples/iOS/Resources/RecipeData/Recipes.sqlite -------------------------------------------------------------------------------- /Samples/iOS/Resources/RecipeData/TemperatureData.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | f 7 | 225 8 | c 9 | 110 10 | g 11 | 1/4 12 | d 13 | Very Slow 14 | 15 | 16 | f 17 | 250 18 | c 19 | 120 20 | g 21 | 1/2 22 | d 23 | Very Slow 24 | 25 | 26 | f 27 | 275 28 | c 29 | 140 30 | g 31 | 1 32 | d 33 | Slow 34 | 35 | 36 | f 37 | 300 38 | c 39 | 150 40 | g 41 | 2 42 | d 43 | Slow 44 | 45 | 46 | f 47 | 325 48 | c 49 | 160 50 | g 51 | 3 52 | d 53 | Moderate 54 | 55 | 56 | f 57 | 350 58 | c 59 | 180 60 | g 61 | 4 62 | d 63 | Moderate 64 | 65 | 66 | f 67 | 375 68 | c 69 | 190 70 | g 71 | 5 72 | d 73 | Moderately Hot 74 | 75 | 76 | f 77 | 400 78 | c 79 | 200 80 | g 81 | 6 82 | d 83 | Moderately Hot 84 | 85 | 86 | f 87 | 425 88 | c 89 | 220 90 | g 91 | 7 92 | d 93 | Hot 94 | 95 | 96 | f 97 | 450 98 | c 99 | 230 100 | g 101 | 8 102 | d 103 | Hot 104 | 105 | 106 | f 107 | 475 108 | c 109 | 240 110 | g 111 | 9 112 | d 113 | Very Hot 114 | 115 | 116 | 117 | -------------------------------------------------------------------------------- /Samples/iOS/Resources/images/Icon-72.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/magicalpanda/MagicalRecord/6031f608b79c1d6802007aaed6efd100e11f59ba/Samples/iOS/Resources/images/Icon-72.png -------------------------------------------------------------------------------- /Samples/iOS/Resources/images/Icon-Small-50.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/magicalpanda/MagicalRecord/6031f608b79c1d6802007aaed6efd100e11f59ba/Samples/iOS/Resources/images/Icon-Small-50.png -------------------------------------------------------------------------------- /Samples/iOS/Resources/images/Icon-Small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/magicalpanda/MagicalRecord/6031f608b79c1d6802007aaed6efd100e11f59ba/Samples/iOS/Resources/images/Icon-Small.png -------------------------------------------------------------------------------- /Samples/iOS/Resources/images/Icon-Small@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/magicalpanda/MagicalRecord/6031f608b79c1d6802007aaed6efd100e11f59ba/Samples/iOS/Resources/images/Icon-Small@2x.png -------------------------------------------------------------------------------- /Samples/iOS/Resources/images/Icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/magicalpanda/MagicalRecord/6031f608b79c1d6802007aaed6efd100e11f59ba/Samples/iOS/Resources/images/Icon.png -------------------------------------------------------------------------------- /Samples/iOS/Resources/images/Icon@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/magicalpanda/MagicalRecord/6031f608b79c1d6802007aaed6efd100e11f59ba/Samples/iOS/Resources/images/Icon@2x.png -------------------------------------------------------------------------------- /Samples/iOS/Resources/images/choosePhoto.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/magicalpanda/MagicalRecord/6031f608b79c1d6802007aaed6efd100e11f59ba/Samples/iOS/Resources/images/choosePhoto.png -------------------------------------------------------------------------------- /Samples/iOS/Resources/images/convert.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/magicalpanda/MagicalRecord/6031f608b79c1d6802007aaed6efd100e11f59ba/Samples/iOS/Resources/images/convert.png -------------------------------------------------------------------------------- /Samples/iOS/Resources/images/fork.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/magicalpanda/MagicalRecord/6031f608b79c1d6802007aaed6efd100e11f59ba/Samples/iOS/Resources/images/fork.png -------------------------------------------------------------------------------- /Samples/iOS/Resources/images/iTunesArtwork: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/magicalpanda/MagicalRecord/6031f608b79c1d6802007aaed6efd100e11f59ba/Samples/iOS/Resources/images/iTunesArtwork -------------------------------------------------------------------------------- /Support/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | $(CURRENT_PROJECT_VERSION) 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 0 23 | NSHumanReadableCopyright 24 | Copyright © 2015 Magical Panda Software LLC. All rights reserved. 25 | NSPrincipalClass 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /Support/Scripts/push_podspec.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | source ~/.rvm/scripts/rvm 4 | rvm use default 5 | pod trunk push 6 | -------------------------------------------------------------------------------- /Support/Scripts/set_version_information.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | git=$(sh /etc/profile; which git) 4 | number_of_commits=$("$git" rev-list HEAD --count) 5 | git_release_version=$("$git" describe --tags --always --abbrev=0) 6 | 7 | target_plist="$TARGET_BUILD_DIR/$INFOPLIST_PATH" 8 | dsym_plist="$DWARF_DSYM_FOLDER_PATH/$DWARF_DSYM_FILE_NAME/Contents/Info.plist" 9 | 10 | for plist in "$target_plist" "$dsym_plist"; do 11 | if [ -f "$plist" ]; then 12 | /usr/libexec/PlistBuddy -c "Set :CFBundleVersion $number_of_commits" "$plist" 13 | /usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString ${git_release_version#*v}" "$plist" 14 | fi 15 | done 16 | -------------------------------------------------------------------------------- /Tests/Core/MagicalRecord+ShorthandTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Tony Arnold on 28/01/2016. 3 | // Copyright © 2016 Magical Panda Software LLC. All rights reserved. 4 | 5 | #import "MagicalRecordTestBase.h" 6 | #import "NSManagedObject+MagicalRecord.h" 7 | #import "MagicalRecord+ShorthandMethods.h" 8 | #import "MagicalRecordShorthandMethodAliases.h" 9 | 10 | @interface MagicalRecordShorthandTests : MagicalRecordTestBase 11 | 12 | @end 13 | 14 | @implementation MagicalRecordShorthandTests 15 | 16 | - (void)setUp 17 | { 18 | [super setUp]; 19 | [MagicalRecord enableShorthandMethods]; 20 | } 21 | 22 | - (void)testLongFormMethodsAreStillAvailableWhenShorthandIsEnabled 23 | { 24 | XCTAssertTrue([[NSManagedObjectContext class] respondsToSelector:@selector(MR_rootSavingContext)]); 25 | XCTAssertTrue([[NSManagedObjectContext MR_rootSavingContext] respondsToSelector:@selector(MR_saveWithBlock:)]); 26 | } 27 | 28 | - (void)testShorthandMethodsAreAvailableWhenEnabled 29 | { 30 | XCTAssertTrue([[NSManagedObjectContext class] respondsToSelector:@selector(rootSavingContext)]); 31 | XCTAssertNotNil([NSManagedObjectContext rootSavingContext]); 32 | XCTAssertTrue([[NSManagedObjectContext rootSavingContext] respondsToSelector:@selector(saveWithBlock:)]); 33 | } 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /Tests/Core/MagicalRecordTestBase.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Tony Arnold on 21/12/2013. 3 | // Copyright (c) 2013 Magical Panda Software LLC. All rights reserved. 4 | // 5 | 6 | #import 7 | #import 8 | #import 9 | 10 | @interface MagicalRecordTestBase : XCTestCase 11 | 12 | @end 13 | -------------------------------------------------------------------------------- /Tests/Core/MagicalRecordTestBase.m: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Tony Arnold on 21/12/2013. 3 | // Copyright (c) 2013 Magical Panda Software LLC. All rights reserved. 4 | // 5 | 6 | #import "MagicalRecordTestBase.h" 7 | #import "MagicalRecordLogging.h" 8 | 9 | @implementation MagicalRecordTestBase 10 | 11 | - (void)setUp 12 | { 13 | [super setUp]; 14 | 15 | // Don't pollute the tests with logging 16 | [MagicalRecord setLoggingLevel:MagicalRecordLoggingLevelOff]; 17 | 18 | // Setup the default model from the current class' bundle 19 | [MagicalRecord setDefaultModelFromClass:[self class]]; 20 | 21 | // Setup a default in-memory store 22 | [MagicalRecord setupCoreDataStackWithInMemoryStore]; 23 | } 24 | 25 | - (void)tearDown 26 | { 27 | [MagicalRecord cleanUp]; 28 | 29 | [super tearDown]; 30 | } 31 | 32 | @end 33 | -------------------------------------------------------------------------------- /Tests/Core/NSManagedObject+MagicalRecordTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Tony Arnold on 11/04/2014. 3 | // Copyright (c) 2014 Magical Panda Software LLC. All rights reserved. 4 | // 5 | 6 | #import "MagicalRecordTestBase.h" 7 | #import "NSManagedObject+MagicalRecord.h" 8 | 9 | #import "DifferentClassNameMapping.h" 10 | #import "EntityWithoutEntityNameMethod.h" 11 | 12 | @interface NSManagedObjectMagicalRecord : MagicalRecordTestBase 13 | 14 | @end 15 | 16 | @implementation NSManagedObjectMagicalRecord 17 | 18 | // +[NSManagedObject(_PFDynamicAccessorsAndPropertySupport) entityName] was subsequently added in iOS 10 and macOS 10.12 19 | // so this expectation has become obsolete 20 | /* 21 | - (void)testThatInternalEntityNameReturnsClassNameWhenEntityNameMethodIsNotImplemented 22 | { 23 | XCTAssertNotNil([EntityWithoutEntityNameMethod MR_entityName]); 24 | XCTAssertEqualObjects([EntityWithoutEntityNameMethod MR_entityName], NSStringFromClass([EntityWithoutEntityNameMethod class])); 25 | } 26 | */ 27 | 28 | - (void)testThatInternalEntityNameReturnsProvidedNameWhenEntityNameMethodIsImplemented 29 | { 30 | XCTAssertNotNil([EntityWithoutEntityNameMethod MR_entityName]); 31 | XCTAssertNotEqualObjects([DifferentClassNameMapping MR_entityName], NSStringFromClass([DifferentClassNameMapping class])); 32 | XCTAssertEqualObjects([DifferentClassNameMapping MR_entityName], [DifferentClassNameMapping entityName]); 33 | } 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /Tests/Core/NSManagedObject+MagicalRequestTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSManagedObject+MagicalRequestTests.m 3 | // MagicalRecord 4 | // 5 | // Created by Sam Dean on 30/07/2016. 6 | // Copyright © 2016 Magical Panda Software LLC. All rights reserved. 7 | // 8 | 9 | #import "MagicalRecordTestBase.h" 10 | 11 | #import "NSManagedObject+MagicalRequests.h" 12 | 13 | @interface NSManagedObject_MagicalRequestTests : MagicalRecordTestBase 14 | 15 | @end 16 | 17 | @implementation NSManagedObject_MagicalRequestTests 18 | 19 | - (void)testThatAscendingParameterIsHonouredForMultipleKeys { 20 | NSManagedObjectContext *context = [NSManagedObjectContext MR_defaultContext]; 21 | 22 | NSPredicate *predicate = [NSPredicate predicateWithValue:YES]; 23 | 24 | // Deliberately expect the default ascending value (YES) to be used for key3 25 | // (not the carried over NO from key2) 26 | NSFetchRequest *request = [NSManagedObject MR_requestAllSortedBy:@"key1:YES,key2:NO,key3" 27 | ascending:YES 28 | withPredicate:predicate 29 | inContext:context]; 30 | 31 | XCTAssertEqual(request.sortDescriptors[0].ascending, YES); 32 | XCTAssertEqual(request.sortDescriptors[1].ascending, NO); 33 | XCTAssertEqual(request.sortDescriptors[2].ascending, YES); 34 | 35 | XCTAssertEqualObjects(request.sortDescriptors[0].key, @"key1"); 36 | XCTAssertEqualObjects(request.sortDescriptors[1].key, @"key2"); 37 | XCTAssertEqualObjects(request.sortDescriptors[2].key, @"key3"); 38 | } 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /Tests/Core/NSManagedObjectContext+ChainSaveTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSManagedObjectContext+ChainSaveTests.m 3 | // MagicalRecord 4 | // 5 | // Created by Lee on 12/1/14. 6 | // Copyright (c) 2014 Magical Panda Software LLC. All rights reserved. 7 | // 8 | 9 | #import "MagicalRecordTestBase.h" 10 | #import "NSManagedObjectContext+MagicalChainSave.h" 11 | #import "SingleEntityWithNoRelationships.h" 12 | 13 | @interface NSManagedObjectContext_ChainSaveTests : MagicalRecordTestBase 14 | 15 | @end 16 | 17 | @implementation NSManagedObjectContext_ChainSaveTests 18 | 19 | - (void)testChainSave 20 | { 21 | XCTestExpectation *expectation = [self expectationWithDescription:@"Chain Save Completed"]; 22 | 23 | //Test if a new Object can save from child context to parent context 24 | __block NSManagedObjectID *childObjectID; 25 | 26 | NSManagedObjectContext *defaultContext = [NSManagedObjectContext MR_defaultContext]; 27 | 28 | [defaultContext MR_saveWithBlock:^(NSManagedObjectContext *localContext) { 29 | SingleEntityWithNoRelationships *insertedObject = [SingleEntityWithNoRelationships MR_createEntityInContext:localContext]; 30 | 31 | XCTAssertTrue(insertedObject.hasChanges); 32 | 33 | NSError *obtainIDsError; 34 | BOOL obtainIDsResult = [localContext obtainPermanentIDsForObjects:@[ insertedObject ] error:&obtainIDsError]; 35 | 36 | XCTAssertTrue(obtainIDsResult); 37 | XCTAssertNil(obtainIDsError); 38 | 39 | childObjectID = [insertedObject objectID]; 40 | 41 | XCTAssertNotNil(childObjectID); 42 | XCTAssertFalse(childObjectID.isTemporaryID); 43 | 44 | } completion:^(BOOL success, NSError *error) { 45 | 46 | //test parent and root saving context 47 | SingleEntityWithNoRelationships *parentObject = (SingleEntityWithNoRelationships *)[defaultContext objectWithID:childObjectID]; 48 | 49 | XCTAssertNotNil(parentObject); 50 | 51 | NSManagedObjectContext *rootSavingContext = [NSManagedObjectContext MR_rootSavingContext]; 52 | 53 | [rootSavingContext performBlockAndWait:^{ 54 | SingleEntityWithNoRelationships *rootObject = (SingleEntityWithNoRelationships *)[rootSavingContext objectWithID:childObjectID]; 55 | 56 | XCTAssertNotNil(rootObject); 57 | }]; 58 | 59 | [expectation fulfill]; 60 | }]; 61 | 62 | [self waitForExpectationsWithTimeout:5.0f handler:nil]; 63 | } 64 | 65 | @end 66 | -------------------------------------------------------------------------------- /Tests/Core/NSManagedObjectContextHelperTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSManagedObjectContextHelperTests.m 3 | // Magical Record 4 | // 5 | // Created by Saul Mora on 7/15/11. 6 | // Copyright 2011 Magical Panda Software LLC. All rights reserved. 7 | // 8 | 9 | #import "MagicalRecordTestBase.h" 10 | #import "SingleEntityWithNoRelationships.h" 11 | 12 | @interface NSManagedObjectContextHelperTests : MagicalRecordTestBase 13 | 14 | @end 15 | 16 | 17 | @implementation NSManagedObjectContextHelperTests 18 | 19 | - (void) testCanCreateContextForCurrentThread 20 | { 21 | #pragma clang diagnostic push 22 | #pragma clang diagnostic ignored "-Wdeprecated-declarations" 23 | NSManagedObjectContext *firstContext = [NSManagedObjectContext MR_contextForCurrentThread]; 24 | NSManagedObjectContext *secondContext = [NSManagedObjectContext MR_contextForCurrentThread]; 25 | #pragma clang diagnostic pop 26 | 27 | XCTAssertEqualObjects(firstContext, secondContext, @"Contexts should be equal"); 28 | } 29 | 30 | - (void) testCanNotifyDefaultContextOnSave 31 | { 32 | NSManagedObjectContext *testContext = [NSManagedObjectContext MR_contextWithParent:[NSManagedObjectContext MR_defaultContext]]; 33 | 34 | XCTAssertEqualObjects([testContext parentContext], [NSManagedObjectContext MR_defaultContext], @"Parent context should be the default context"); 35 | } 36 | 37 | - (void) testThatSavedObjectsHavePermanentIDs 38 | { 39 | NSManagedObjectContext *context = [NSManagedObjectContext MR_defaultContext]; 40 | SingleEntityWithNoRelationships *entity = [SingleEntityWithNoRelationships MR_createEntityInContext:context]; 41 | 42 | XCTAssertTrue([[entity objectID] isTemporaryID], @"Entity should have a temporary ID before saving"); 43 | [context MR_saveOnlySelfAndWait]; 44 | XCTAssertFalse([[entity objectID] isTemporaryID], @"Entity should not have a temporary ID after saving"); 45 | } 46 | 47 | 48 | @end 49 | -------------------------------------------------------------------------------- /Tests/DataImport/ImportMultipleEntitiesWithNoPrimaryKeyTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // ImportMultipleEntitiesWithNoPrimaryKeyTests.m 3 | // MagicalRecord 4 | // 5 | // Created by Sérgio Estêvão on 09/01/2014. 6 | // Copyright (c) 2014 Magical Panda Software LLC. All rights reserved. 7 | // 8 | 9 | #import "MagicalDataImportTestCase.h" 10 | #import 11 | #import "FixtureHelpers.h" 12 | #import "SingleEntityWithNoRelationships.h" 13 | 14 | @interface ImportMultipleEntitiesWithNoPrimaryKeyTests : MagicalDataImportTestCase 15 | 16 | @property (nonatomic, retain) NSArray * arrayOfTestEntity; 17 | 18 | @end 19 | 20 | @implementation ImportMultipleEntitiesWithNoPrimaryKeyTests 21 | 22 | - (void)setUp 23 | { 24 | [super setUp]; 25 | 26 | self.arrayOfTestEntity = [SingleEntityWithNoRelationships MR_importFromArray:self.testEntityData]; 27 | } 28 | 29 | - (void)tearDown 30 | { 31 | [super tearDown]; 32 | } 33 | 34 | - (void)testImportOfMultipleEntities 35 | { 36 | XCTAssertNotNil(self.arrayOfTestEntity, @"arrayOfTestEntity should not be nil"); 37 | XCTAssertEqual(self.arrayOfTestEntity.count, (NSUInteger)4, @"arrayOfTestEntity should have 4 entities"); 38 | } 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /Tests/DataImport/ImportSingleEntityRelatedToManyMappedEntitiesUsingMappedPrimaryKeyTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // Import SingleEntityRelatedToManyMappedEntitiesUsingMappedPrimaryKeyTests.m 3 | // Magical Record 4 | // 5 | // Created by Saul Mora on 8/16/11. 6 | // Copyright 2011 Magical Panda Software LLC. All rights reserved. 7 | // 8 | 9 | #import "SingleEntityRelatedToManyMappedEntitiesUsingMappedPrimaryKey.h" 10 | #import "MagicalDataImportTestCase.h" 11 | 12 | @interface ImportSingleEntityRelatedToManyMappedEntitiesUsingMappedPrimaryKeyTests : MagicalDataImportTestCase 13 | 14 | @end 15 | 16 | @implementation ImportSingleEntityRelatedToManyMappedEntitiesUsingMappedPrimaryKeyTests 17 | 18 | - (Class)testEntityClass 19 | { 20 | return [SingleEntityRelatedToManyMappedEntitiesUsingMappedPrimaryKey class]; 21 | } 22 | 23 | - (void)testImportData 24 | { 25 | SingleEntityRelatedToManyMappedEntitiesUsingMappedPrimaryKey *entity = [[self testEntityClass] MR_importFromObject:self.testEntityData inContext:[NSManagedObjectContext MR_defaultContext]]; 26 | 27 | XCTAssertNotNil(entity, @"Entity should not be nil"); 28 | 29 | XCTestExpectation *expectation = [self expectationWithDescription:@"Wait for managed object context"]; 30 | 31 | [entity.managedObjectContext performBlock:^{ 32 | NSUInteger mappedEntitiesCount = entity.mappedEntities.count; 33 | XCTAssertEqual(mappedEntitiesCount, (NSUInteger)4, @"Expected 4 mapped entities, received %zd", mappedEntitiesCount); 34 | 35 | [expectation fulfill]; 36 | }]; 37 | 38 | [self waitForExpectationsWithTimeout:5.0 handler:^(NSError * _Nullable error) { 39 | MRLogError(@"Managed Object Context performBlock: timed out due to error: %@", [error localizedDescription]); 40 | }]; 41 | } 42 | 43 | - (void)testImportNilData 44 | { 45 | SingleEntityRelatedToManyMappedEntitiesUsingMappedPrimaryKey *entity = [[self testEntityClass] MR_importFromObject:self.testEntityData inContext:[NSManagedObjectContext MR_defaultContext]]; 46 | 47 | XCTAssertNotNil(entity, @"Entity should not be nil"); 48 | 49 | [entity.managedObjectContext performBlockAndWait:^{ 50 | // testing that importing nothing will not change the relationship 51 | [entity MR_importValuesForKeysWithObject:@{}]; 52 | NSUInteger mappedEntitiesCount = entity.mappedEntities.count; 53 | XCTAssertEqual(mappedEntitiesCount, (NSUInteger)4, @"Expected 4 mapped entities, received %zd", mappedEntitiesCount); 54 | 55 | // testing that importing `null` will nullify the relationship 56 | [entity MR_importValuesForKeysWithObject:@{@"mappedEntities":[NSNull null]}]; 57 | mappedEntitiesCount = entity.mappedEntities.count; 58 | XCTAssertEqual(mappedEntitiesCount, (NSUInteger)0, @"Expected 0 mapped entities, received %zd", mappedEntitiesCount); 59 | }]; 60 | } 61 | 62 | @end 63 | -------------------------------------------------------------------------------- /Tests/DataImport/ImportSingleEntityRelatedToMappedEntityUsingDefaultsTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // ImportSingleEntityRelatedToMappedEntityUsingDefaults.m 3 | // Magical Record 4 | // 5 | // Created by Saul Mora on 8/11/11. 6 | // Copyright (c) 2011 Magical Panda Software LLC. All rights reserved. 7 | // 8 | 9 | #import "MappedEntity.h" 10 | #import "SingleEntityRelatedToMappedEntityUsingDefaults.h" 11 | #import "MagicalDataImportTestCase.h" 12 | 13 | @interface ImportSingleEntityRelatedToMappedEntityUsingDefaultsTests : MagicalDataImportTestCase 14 | 15 | @end 16 | 17 | @implementation ImportSingleEntityRelatedToMappedEntityUsingDefaultsTests 18 | 19 | - (Class)testEntityClass 20 | { 21 | return [SingleEntityRelatedToMappedEntityUsingDefaults class]; 22 | } 23 | 24 | - (void)setupTestData 25 | { 26 | NSManagedObjectContext *context = [NSManagedObjectContext MR_defaultContext]; 27 | 28 | MappedEntity *testMappedEntity = [MappedEntity MR_createEntityInContext:context]; 29 | 30 | testMappedEntity.mappedEntityID = @42; 31 | testMappedEntity.sampleAttribute = @"This attribute created as part of the test case setup"; 32 | 33 | SingleEntityRelatedToMappedEntityUsingDefaults *entity = [SingleEntityRelatedToMappedEntityUsingDefaults MR_createEntityInContext:context]; 34 | entity.singleEntityRelatedToMappedEntityUsingDefaultsID = @24; 35 | 36 | [context MR_saveToPersistentStoreAndWait]; 37 | } 38 | 39 | - (void)testImportMappedEntityViaToOneRelationship 40 | { 41 | SingleEntityRelatedToMappedEntityUsingDefaults *entity = [[self testEntityClass] MR_importFromObject:self.testEntityData]; 42 | 43 | XCTestExpectation *expectation = [self expectationWithDescription:@"Wait for managed object context"]; 44 | 45 | [entity.managedObjectContext performBlock:^{ 46 | MappedEntity *testRelatedEntity = entity.mappedEntity; 47 | 48 | XCTAssertNotNil(testRelatedEntity, @"Entity should not be nil"); 49 | 50 | NSString *string = testRelatedEntity.sampleAttribute; 51 | NSRange stringRange = [string rangeOfString:@"sample json file"]; 52 | 53 | XCTAssert(stringRange.length > 0, @"Could not find 'sample json file' in '%@'", string); 54 | 55 | NSNumber *numberOfEntities = [MappedEntity MR_numberOfEntities]; 56 | XCTAssertEqualObjects(numberOfEntities, @1, @"Expected 1 entity, got %@", numberOfEntities); 57 | 58 | [expectation fulfill]; 59 | }]; 60 | 61 | [self waitForExpectationsWithTimeout:5.0 handler:^(NSError * _Nullable error) { 62 | MRLogError(@"Managed Object Context performBlock: timed out due to error: %@", [error localizedDescription]); 63 | }]; 64 | } 65 | 66 | @end 67 | -------------------------------------------------------------------------------- /Tests/DataImport/ImportSingleEntityRelatedToMappedEntityWithNestedMappedAttributesTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // ImportSingleEntityRelatedToMappedEntityWithNestedMappedAttributesTests.m 3 | // Magical Record 4 | // 5 | // Created by Saul Mora on 8/16/11. 6 | // Copyright (c) 2011 Magical Panda Software LLC. All rights reserved. 7 | // 8 | 9 | #import "MagicalDataImportTestCase.h" 10 | #import "MappedEntity.h" 11 | #import "SingleEntityRelatedToMappedEntityWithNestedMappedAttributes.h" 12 | 13 | @interface ImportSingleEntityRelatedToMappedEntityWithNestedMappedAttributesTests : MagicalDataImportTestCase 14 | 15 | @end 16 | 17 | @implementation ImportSingleEntityRelatedToMappedEntityWithNestedMappedAttributesTests 18 | 19 | - (Class)testEntityClass 20 | { 21 | return [SingleEntityRelatedToMappedEntityWithNestedMappedAttributes class]; 22 | } 23 | 24 | - (void)testDataImport 25 | { 26 | SingleEntityRelatedToMappedEntityWithNestedMappedAttributes *entity = [[self testEntityClass] MR_importFromObject:self.testEntityData]; 27 | 28 | XCTestExpectation *expectation = [self expectationWithDescription:@"Wait for managed object context"]; 29 | 30 | [entity.managedObjectContext performBlock:^{ 31 | XCTAssertNotNil(entity.mappedEntity, @"mappedEntity should not be nil"); 32 | XCTAssertEqualObjects(entity.mappedEntity.mappedEntityID, @42, @"Expected mappedEntityID to be 42, got %@", entity.mappedEntity.mappedEntityID); 33 | 34 | NSRange stringRange = [entity.mappedEntity.nestedAttribute rangeOfString:@"nested value"]; 35 | XCTAssertTrue(stringRange.length > 0, @"nestedAttribute did not contain 'nested value': %@", entity.mappedEntity.nestedAttribute); 36 | 37 | [expectation fulfill]; 38 | }]; 39 | 40 | [self waitForExpectationsWithTimeout:5.0 handler:^(NSError * _Nullable error) { 41 | MRLogError(@"Managed Object Context performBlock: timed out due to error: %@", [error localizedDescription]); 42 | }]; 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /Tests/DataImport/ImportSingleEntityRelatedToMappedEntityWithSecondaryMappingsTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // ImportSingleEntityRelatedToMappedEntityWithSecondaryMappingsTests.m 3 | // Magical Record 4 | // 5 | // Created by Saul Mora on 8/18/11. 6 | // Copyright (c) 2011 Magical Panda Software LLC. All rights reserved. 7 | // 8 | #import "MagicalDataImportTestCase.h" 9 | #import "SingleEntityRelatedToMappedEntityWithSecondaryMappings.h" 10 | #import "MappedEntity.h" 11 | 12 | @interface ImportSingleEntityRelatedToMappedEntityWithSecondaryMappingsTests : MagicalDataImportTestCase 13 | 14 | @end 15 | 16 | @implementation ImportSingleEntityRelatedToMappedEntityWithSecondaryMappingsTests 17 | 18 | - (Class)testEntityClass 19 | { 20 | return [SingleEntityRelatedToMappedEntityWithSecondaryMappings class]; 21 | } 22 | 23 | - (void)testImportMappedAttributeUsingSecondaryMappedKeyName 24 | { 25 | SingleEntityRelatedToMappedEntityWithSecondaryMappings *entity = [[self testEntityClass] MR_importFromObject:self.testEntityData]; 26 | 27 | [entity.managedObjectContext performBlockAndWait:^{ 28 | XCTAssertNotNil(entity, @"Entity should not be nil"); 29 | 30 | NSRange stringRange = [[entity secondaryMappedAttribute] rangeOfString:@"sample json file"]; 31 | XCTAssertTrue(stringRange.length > 0, @"Expected string not contained within secondary mapped attribute. Got %@", [entity secondaryMappedAttribute]); 32 | }]; 33 | } 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /Tests/DataImport/MagicalDataImportTestCase.h: -------------------------------------------------------------------------------- 1 | // 2 | // MagicalDataImportTestCase.h 3 | // Magical Record 4 | // 5 | // Created by Saul Mora on 8/16/11. 6 | // Copyright (c) 2011 Magical Panda Software LLC. All rights reserved. 7 | // 8 | 9 | #import "MagicalRecordTestBase.h" 10 | 11 | @interface MagicalDataImportTestCase : MagicalRecordTestBase 12 | 13 | @property (nonatomic, strong) id testEntityData; 14 | @property (nonatomic, strong) id testEntity; 15 | 16 | - (Class) testEntityClass; 17 | - (void) setupTestData; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /Tests/DataImport/MagicalDataImportTestCase.m: -------------------------------------------------------------------------------- 1 | // 2 | // MagicalDataImportTestCase.m 3 | // Magical Record 4 | // 5 | // Created by Saul Mora on 8/16/11. 6 | // Copyright (c) 2011 Magical Panda Software LLC. All rights reserved. 7 | // 8 | 9 | #import "MagicalDataImportTestCase.h" 10 | #import "FixtureHelpers.h" 11 | 12 | @implementation MagicalDataImportTestCase 13 | 14 | - (void)setUp 15 | { 16 | [super setUp]; 17 | 18 | [self setupTestData]; 19 | 20 | self.testEntityData = [self dataFromJSONFixture]; 21 | } 22 | 23 | - (Class)testEntityClass 24 | { 25 | return [NSManagedObject class]; 26 | } 27 | 28 | - (void)setupTestData 29 | { 30 | // Implement this in your subclasses 31 | } 32 | 33 | @end 34 | -------------------------------------------------------------------------------- /Tests/Fixtures/FixtureHelpers.h: -------------------------------------------------------------------------------- 1 | // 2 | // FixtureHelpers.h 3 | // Magical Record 4 | // 5 | // Created by Saul Mora on 7/15/11. 6 | // Copyright 2011 Magical Panda Software LLC. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface FixtureHelpers : NSObject 12 | 13 | + (id) dataFromPListFixtureNamed:(NSString *)fixtureName; 14 | + (id) dataFromJSONFixtureNamed:(NSString *)fixtureName; 15 | 16 | @end 17 | 18 | @interface XCTest (FixtureHelpers) 19 | 20 | - (id) dataFromJSONFixture; 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /Tests/Fixtures/FixtureHelpers.m: -------------------------------------------------------------------------------- 1 | // 2 | // FixtureHelpers.m 3 | // Magical Record 4 | // 5 | // Created by Saul Mora on 7/15/11. 6 | // Copyright 2011 Magical Panda Software LLC. All rights reserved. 7 | // 8 | 9 | #import "FixtureHelpers.h" 10 | 11 | @implementation FixtureHelpers 12 | 13 | + (id) dataFromPListFixtureNamed:(NSString *)fixtureName 14 | { 15 | NSBundle *testBundle = [NSBundle bundleForClass:[self class]]; 16 | NSString *resource = [testBundle pathForResource:fixtureName ofType:@"plist"]; 17 | NSData *plistData = [NSData dataWithContentsOfFile:resource]; 18 | 19 | return [NSPropertyListSerialization propertyListWithData:plistData options:NSPropertyListImmutable format:nil error:nil]; 20 | } 21 | 22 | + (id) dataFromJSONFixtureNamed:(NSString *)fixtureName 23 | { 24 | NSBundle *testBundle = [NSBundle bundleForClass:[self class]]; 25 | NSString *resource = [testBundle pathForResource:fixtureName ofType:@"json"]; 26 | NSInputStream *inputStream = [NSInputStream inputStreamWithFileAtPath:resource]; 27 | [inputStream open]; 28 | 29 | return [NSJSONSerialization JSONObjectWithStream:inputStream options:0 error:nil]; 30 | } 31 | 32 | @end 33 | 34 | @implementation XCTest (FixtureHelpers) 35 | 36 | - (id) dataFromJSONFixture 37 | { 38 | NSString *className = NSStringFromClass([self class]); 39 | className = [className stringByReplacingOccurrencesOfString:@"Import" withString:@""]; 40 | className = [className stringByReplacingOccurrencesOfString:@"Spec" withString:@""]; 41 | className = [className stringByReplacingOccurrencesOfString:@"Tests" withString:@""]; 42 | return [FixtureHelpers dataFromJSONFixtureNamed:className]; 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /Tests/Fixtures/MultipleEntitiesWithNoPrimaryKey.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "stringTestAttribute": "This is a test value", 4 | }, 5 | { 6 | "stringTestAttribute": "This is a test value", 7 | }, 8 | { 9 | "stringTestAttribute": "This is a test value", 10 | }, 11 | { 12 | "stringTestAttribute": "This is a test value", 13 | } 14 | ] -------------------------------------------------------------------------------- /Tests/Fixtures/SampleJSONDataForImport.json: -------------------------------------------------------------------------------- 1 | { 2 | 3 | } -------------------------------------------------------------------------------- /Tests/Fixtures/SingleEntityRelatedToManyMappedEntitiesUsingListOfPrimaryKeys.json: -------------------------------------------------------------------------------- 1 | { 2 | "mappedEntities": [1,2,3,4], 3 | "testPrimaryKey": 84 4 | } -------------------------------------------------------------------------------- /Tests/Fixtures/SingleEntityRelatedToManyMappedEntitiesUsingMappedPrimaryKey.json: -------------------------------------------------------------------------------- 1 | { 2 | "mappedEntities": 3 | [ 4 | { 5 | "id": 1, 6 | "sampleAttribute": "Sample Attribute Value 1" 7 | } 8 | , 9 | { 10 | "id": 2, 11 | "sampleAttribute": "Sample Attribute Value 2" 12 | } 13 | , 14 | { 15 | "id": 3, 16 | "sampleAttribute": "Sample Attribute Value 3" 17 | } 18 | , 19 | { 20 | "id": 4, 21 | "sampleAttribute": "Sample Attribute Value 4" 22 | } 23 | ] 24 | } -------------------------------------------------------------------------------- /Tests/Fixtures/SingleEntityRelatedToMappedEntityUsingDefaults.json: -------------------------------------------------------------------------------- 1 | { 2 | "mappedEntity": 3 | { 4 | "mappedEntityID": 42, 5 | "sampleAttribute": "This is from the sample json file" 6 | } 7 | } -------------------------------------------------------------------------------- /Tests/Fixtures/SingleEntityRelatedToMappedEntityUsingMappedPrimaryKey.json: -------------------------------------------------------------------------------- 1 | { 2 | "someRandomAttributeName": 3 | { 4 | "id": 42, 5 | "sampleAttribute": "This is from the sample json file" 6 | } 7 | } -------------------------------------------------------------------------------- /Tests/Fixtures/SingleEntityRelatedToMappedEntityWithNestedMappedAttributes.json: -------------------------------------------------------------------------------- 1 | { 2 | "mappedEntity": 3 | { 4 | "mappedEntityID": 42, 5 | "attributeValue": 6 | { 7 | "nestedValue": "This is a nested value" 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /Tests/Fixtures/SingleEntityRelatedToMappedEntityWithSecondaryMappings.json: -------------------------------------------------------------------------------- 1 | { 2 | "actualMappedKey": "mapped value from sample json file", 3 | "actualRelatedObject": 4 | { 5 | "id": 50, 6 | "sampleAttribute": "actualMappedRelationship value from sample json file" 7 | } 8 | } -------------------------------------------------------------------------------- /Tests/Fixtures/SingleEntityWithNoRelationships.json: -------------------------------------------------------------------------------- 1 | { 2 | "int64TestAttribute": 10158365420975381, 3 | "stringTestAttribute": "This is a test value", 4 | "int32TestAttribute": 32, 5 | "int16TestAttribute": 256, 6 | "decimalTestAttribute": 1.2, 7 | "doubleTestAttribute": 124.3, 8 | "floatTestAttribute": 10000000000, 9 | "booleanTestAttribute": false, 10 | "dateTestAttribute": "2011-07-23T22:30:40Z", 11 | "colorTestAttribute": "rgba(64,128,225,1)", 12 | "mappedAttributeWithStringValue": "Mapped value", 13 | "dateWithCustomFormat": "8/5/2011 1-56-04", 14 | "nullTestAttribute": null, 15 | "int64AsStringTestAttribute": "42", 16 | "int32AsStringTestAttribute": "32", 17 | "int16AsStringTestAttribute": "256", 18 | "decimalAsStringTestAttribute": "1.2", 19 | "doubleAsStringTestAttribute": "124.3", 20 | "floatAsStringTestAttribute": "10000000000", 21 | "numberAsStringTestAttribute" : 10248909829, 22 | "booleanAsStringTestAttribute": "true", 23 | "unixTimeTestAttribute" : 1388349428, 24 | "unixTime13TestAttribute" : 1388349427543 25 | } -------------------------------------------------------------------------------- /Tests/Fixtures/SingleEntityWithNoRelationships.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | numberAsStringTestAttribute 6 | 10248909829 7 | int64TestAttribute 8 | 10158365420975381 9 | stringTestAttribute 10 | This is a test value 11 | int32TestAttribute 12 | 32 13 | int16TestAttribute 14 | 256 15 | decimalTestAttribute 16 | 1.2 17 | doubleTestAttribute 18 | 124.3 19 | floatTestAttribute 20 | 10000000000 21 | booleanTestAttribute 22 | 23 | dateTestAttribute 24 | 2011-07-24T04:30:40Z 25 | colorTestAttribute 26 | rgba(64,128,225,1) 27 | mappedAttributeWithStringValue 28 | Mapped value 29 | dateWithCustomFormat 30 | 8/5/2011 1-56-04 AM 31 | nullTestAttribte 32 | 33 | booleanAsStringTestAttribute 34 | true 35 | 36 | 37 | -------------------------------------------------------------------------------- /Tests/Fixtures/SingleRelatedEntity.json: -------------------------------------------------------------------------------- 1 | { 2 | "testAbstractToOneRelationship": 3 | { 4 | "sampleBaseAttribute": "This should be imported as: BASE ATTRIBUTE TEST", 5 | "sampleConcreteAttribute": "This should be imported as: DESCENDANT ATTRIBUTE TEST" 6 | } 7 | , 8 | "testAbstractToManyRelationship": 9 | [ 10 | { 11 | "sampleBaseAttribute": "Import as BASE ATTRIBUTE TEST 1", 12 | "sampleConcreteAttribute": "Import as DESCENDANT ATTRIBUTE TEST 1" 13 | } 14 | , 15 | { 16 | "sampleBaseAttribute": "Import as BASE ATTRIBUTE TEST 2", 17 | "sampleConcreteAttribute": "Import as DESCENDANT ATTRIBUTE TEST 2" 18 | } 19 | ] 20 | , 21 | "testConcreteToOneRelationship": 22 | { 23 | "sampleBaseAttribute": "Import as BASE ATTRIBUTE TEST", 24 | "sampleConcreteAttribute": "Import as DESCENDANT ATTRIBUTE TEST" 25 | } 26 | , 27 | "testConcreteToManyRelationship": 28 | [ 29 | { 30 | "sampleBaseAttribute": "Import as BASE ATTRIBUTE TEST 1", 31 | "sampleConcreteAttribute": "Import as DESCENDANT ATTRIBUTE TEST 1" 32 | } 33 | , 34 | { 35 | "sampleBaseAttribute": "Import as BASE ATTRIBUTE TEST 2", 36 | "sampleConcreteAttribute": "Import as DESCENDANT ATTRIBUTE TEST 2" 37 | } 38 | , 39 | { 40 | "sampleBaseAttribute": "Import as BASE ATTRIBUTE TEST 3", 41 | "sampleConcreteAttribute": "Import as DESCENDANT ATTRIBUTE TEST 3" 42 | } 43 | ] 44 | } -------------------------------------------------------------------------------- /Tests/Fixtures/TestModel/AbstractRelatedEntity.h: -------------------------------------------------------------------------------- 1 | #import "_AbstractRelatedEntity.h" 2 | 3 | @interface AbstractRelatedEntity : _AbstractRelatedEntity {} 4 | // Custom logic goes here. 5 | @end 6 | -------------------------------------------------------------------------------- /Tests/Fixtures/TestModel/AbstractRelatedEntity.m: -------------------------------------------------------------------------------- 1 | #import "AbstractRelatedEntity.h" 2 | 3 | @interface AbstractRelatedEntity () 4 | 5 | // Private interface goes here. 6 | 7 | @end 8 | 9 | @implementation AbstractRelatedEntity 10 | 11 | // Custom logic goes here. 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /Tests/Fixtures/TestModel/ConcreteRelatedEntity.h: -------------------------------------------------------------------------------- 1 | #import "_ConcreteRelatedEntity.h" 2 | 3 | @interface ConcreteRelatedEntity : _ConcreteRelatedEntity {} 4 | // Custom logic goes here. 5 | @end 6 | -------------------------------------------------------------------------------- /Tests/Fixtures/TestModel/ConcreteRelatedEntity.m: -------------------------------------------------------------------------------- 1 | #import "ConcreteRelatedEntity.h" 2 | 3 | @interface ConcreteRelatedEntity () 4 | 5 | // Private interface goes here. 6 | 7 | @end 8 | 9 | @implementation ConcreteRelatedEntity 10 | 11 | // Custom logic goes here. 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /Tests/Fixtures/TestModel/DifferentClassNameMapping.h: -------------------------------------------------------------------------------- 1 | #import "_DifferentClassNameMapping.h" 2 | 3 | @interface DifferentClassNameMapping : _DifferentClassNameMapping {} 4 | // Custom logic goes here. 5 | @end 6 | -------------------------------------------------------------------------------- /Tests/Fixtures/TestModel/DifferentClassNameMapping.m: -------------------------------------------------------------------------------- 1 | #import "DifferentClassNameMapping.h" 2 | 3 | @interface DifferentClassNameMapping () 4 | 5 | // Private interface goes here. 6 | 7 | @end 8 | 9 | @implementation DifferentClassNameMapping 10 | 11 | // Custom logic goes here. 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /Tests/Fixtures/TestModel/EntityWithoutEntityNameMethod.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Tony Arnold on 11/04/2014. 3 | // Copyright (c) 2014 Magical Panda Software LLC. All rights reserved. 4 | // 5 | 6 | #import 7 | 8 | @interface EntityWithoutEntityNameMethod : NSManagedObject 9 | 10 | @end 11 | -------------------------------------------------------------------------------- /Tests/Fixtures/TestModel/EntityWithoutEntityNameMethod.m: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Tony Arnold on 11/04/2014. 3 | // Copyright (c) 2014 Magical Panda Software LLC. All rights reserved. 4 | // 5 | 6 | #import "EntityWithoutEntityNameMethod.h" 7 | 8 | @implementation EntityWithoutEntityNameMethod 9 | 10 | @end 11 | -------------------------------------------------------------------------------- /Tests/Fixtures/TestModel/MappedEntity.h: -------------------------------------------------------------------------------- 1 | #import "_MappedEntity.h" 2 | 3 | @interface MappedEntity : _MappedEntity {} 4 | // Custom logic goes here. 5 | @end 6 | -------------------------------------------------------------------------------- /Tests/Fixtures/TestModel/MappedEntity.m: -------------------------------------------------------------------------------- 1 | #import "MappedEntity.h" 2 | 3 | @interface MappedEntity () 4 | 5 | // Private interface goes here. 6 | 7 | @end 8 | 9 | @implementation MappedEntity 10 | 11 | // Custom logic goes here. 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /Tests/Fixtures/TestModel/SingleEntityRelatedToManyMappedEntitiesUsingMappedPrimaryKey.h: -------------------------------------------------------------------------------- 1 | #import "_SingleEntityRelatedToManyMappedEntitiesUsingMappedPrimaryKey.h" 2 | 3 | @interface SingleEntityRelatedToManyMappedEntitiesUsingMappedPrimaryKey : _SingleEntityRelatedToManyMappedEntitiesUsingMappedPrimaryKey {} 4 | // Custom logic goes here. 5 | @end 6 | -------------------------------------------------------------------------------- /Tests/Fixtures/TestModel/SingleEntityRelatedToManyMappedEntitiesUsingMappedPrimaryKey.m: -------------------------------------------------------------------------------- 1 | #import "SingleEntityRelatedToManyMappedEntitiesUsingMappedPrimaryKey.h" 2 | 3 | @interface SingleEntityRelatedToManyMappedEntitiesUsingMappedPrimaryKey () 4 | 5 | // Private interface goes here. 6 | 7 | @end 8 | 9 | @implementation SingleEntityRelatedToManyMappedEntitiesUsingMappedPrimaryKey 10 | 11 | // Custom logic goes here. 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /Tests/Fixtures/TestModel/SingleEntityRelatedToMappedEntityUsingDefaults.h: -------------------------------------------------------------------------------- 1 | #import "_SingleEntityRelatedToMappedEntityUsingDefaults.h" 2 | 3 | @interface SingleEntityRelatedToMappedEntityUsingDefaults : _SingleEntityRelatedToMappedEntityUsingDefaults {} 4 | // Custom logic goes here. 5 | @end 6 | -------------------------------------------------------------------------------- /Tests/Fixtures/TestModel/SingleEntityRelatedToMappedEntityUsingDefaults.m: -------------------------------------------------------------------------------- 1 | #import "SingleEntityRelatedToMappedEntityUsingDefaults.h" 2 | 3 | @interface SingleEntityRelatedToMappedEntityUsingDefaults () 4 | 5 | // Private interface goes here. 6 | 7 | @end 8 | 9 | @implementation SingleEntityRelatedToMappedEntityUsingDefaults 10 | 11 | // Custom logic goes here. 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /Tests/Fixtures/TestModel/SingleEntityRelatedToMappedEntityUsingMappedPrimaryKey.h: -------------------------------------------------------------------------------- 1 | #import "_SingleEntityRelatedToMappedEntityUsingMappedPrimaryKey.h" 2 | 3 | @interface SingleEntityRelatedToMappedEntityUsingMappedPrimaryKey : _SingleEntityRelatedToMappedEntityUsingMappedPrimaryKey {} 4 | // Custom logic goes here. 5 | @end 6 | -------------------------------------------------------------------------------- /Tests/Fixtures/TestModel/SingleEntityRelatedToMappedEntityUsingMappedPrimaryKey.m: -------------------------------------------------------------------------------- 1 | #import "SingleEntityRelatedToMappedEntityUsingMappedPrimaryKey.h" 2 | 3 | @interface SingleEntityRelatedToMappedEntityUsingMappedPrimaryKey () 4 | 5 | // Private interface goes here. 6 | 7 | @end 8 | 9 | @implementation SingleEntityRelatedToMappedEntityUsingMappedPrimaryKey 10 | 11 | // Custom logic goes here. 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /Tests/Fixtures/TestModel/SingleEntityRelatedToMappedEntityWithNestedMappedAttributes.h: -------------------------------------------------------------------------------- 1 | #import "_SingleEntityRelatedToMappedEntityWithNestedMappedAttributes.h" 2 | 3 | @interface SingleEntityRelatedToMappedEntityWithNestedMappedAttributes : _SingleEntityRelatedToMappedEntityWithNestedMappedAttributes {} 4 | // Custom logic goes here. 5 | @end 6 | -------------------------------------------------------------------------------- /Tests/Fixtures/TestModel/SingleEntityRelatedToMappedEntityWithNestedMappedAttributes.m: -------------------------------------------------------------------------------- 1 | #import "SingleEntityRelatedToMappedEntityWithNestedMappedAttributes.h" 2 | 3 | @interface SingleEntityRelatedToMappedEntityWithNestedMappedAttributes () 4 | 5 | // Private interface goes here. 6 | 7 | @end 8 | 9 | @implementation SingleEntityRelatedToMappedEntityWithNestedMappedAttributes 10 | 11 | // Custom logic goes here. 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /Tests/Fixtures/TestModel/SingleEntityRelatedToMappedEntityWithSecondaryMappings.h: -------------------------------------------------------------------------------- 1 | #import "_SingleEntityRelatedToMappedEntityWithSecondaryMappings.h" 2 | 3 | @interface SingleEntityRelatedToMappedEntityWithSecondaryMappings : _SingleEntityRelatedToMappedEntityWithSecondaryMappings {} 4 | // Custom logic goes here. 5 | @end 6 | -------------------------------------------------------------------------------- /Tests/Fixtures/TestModel/SingleEntityRelatedToMappedEntityWithSecondaryMappings.m: -------------------------------------------------------------------------------- 1 | #import "SingleEntityRelatedToMappedEntityWithSecondaryMappings.h" 2 | 3 | @interface SingleEntityRelatedToMappedEntityWithSecondaryMappings () 4 | 5 | // Private interface goes here. 6 | 7 | @end 8 | 9 | @implementation SingleEntityRelatedToMappedEntityWithSecondaryMappings 10 | 11 | // Custom logic goes here. 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /Tests/Fixtures/TestModel/SingleEntityWithNoRelationships.h: -------------------------------------------------------------------------------- 1 | #import "_SingleEntityWithNoRelationships.h" 2 | 3 | @interface SingleEntityWithNoRelationships : _SingleEntityWithNoRelationships {} 4 | // Custom logic goes here. 5 | @end 6 | -------------------------------------------------------------------------------- /Tests/Fixtures/TestModel/SingleEntityWithNoRelationships.m: -------------------------------------------------------------------------------- 1 | #import "SingleEntityWithNoRelationships.h" 2 | 3 | @interface SingleEntityWithNoRelationships () 4 | 5 | // Private interface goes here. 6 | 7 | @end 8 | 9 | @implementation SingleEntityWithNoRelationships 10 | 11 | // Custom logic goes here. 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /Tests/Fixtures/TestModel/SingleRelatedEntity.h: -------------------------------------------------------------------------------- 1 | #import "_SingleRelatedEntity.h" 2 | 3 | @interface SingleRelatedEntity : _SingleRelatedEntity {} 4 | // Custom logic goes here. 5 | @end 6 | -------------------------------------------------------------------------------- /Tests/Fixtures/TestModel/SingleRelatedEntity.m: -------------------------------------------------------------------------------- 1 | #import "SingleRelatedEntity.h" 2 | 3 | @interface SingleRelatedEntity () 4 | 5 | // Private interface goes here. 6 | 7 | @end 8 | 9 | @implementation SingleRelatedEntity 10 | 11 | // Custom logic goes here. 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /Tests/Fixtures/TestModel/_AbstractRelatedEntity.h: -------------------------------------------------------------------------------- 1 | // DO NOT EDIT. This file is machine-generated and constantly overwritten. 2 | // Make changes to AbstractRelatedEntity.h instead. 3 | 4 | #import 5 | 6 | extern const struct AbstractRelatedEntityAttributes { 7 | __unsafe_unretained NSString *sampleBaseAttribute; 8 | } AbstractRelatedEntityAttributes; 9 | 10 | @interface AbstractRelatedEntityID : NSManagedObjectID {} 11 | @end 12 | 13 | @interface _AbstractRelatedEntity : NSManagedObject {} 14 | + (id)insertInManagedObjectContext:(NSManagedObjectContext*)moc_; 15 | + (NSString*)entityName; 16 | + (NSEntityDescription*)entityInManagedObjectContext:(NSManagedObjectContext*)moc_; 17 | - (AbstractRelatedEntityID*)objectID; 18 | 19 | @property (nonatomic, strong) NSString* sampleBaseAttribute; 20 | 21 | //- (BOOL)validateSampleBaseAttribute:(id*)value_ error:(NSError**)error_; 22 | 23 | @end 24 | 25 | @interface _AbstractRelatedEntity (CoreDataGeneratedPrimitiveAccessors) 26 | 27 | - (NSString*)primitiveSampleBaseAttribute; 28 | - (void)setPrimitiveSampleBaseAttribute:(NSString*)value; 29 | 30 | @end 31 | -------------------------------------------------------------------------------- /Tests/Fixtures/TestModel/_AbstractRelatedEntity.m: -------------------------------------------------------------------------------- 1 | // DO NOT EDIT. This file is machine-generated and constantly overwritten. 2 | // Make changes to AbstractRelatedEntity.m instead. 3 | 4 | #import "_AbstractRelatedEntity.h" 5 | 6 | const struct AbstractRelatedEntityAttributes AbstractRelatedEntityAttributes = { 7 | .sampleBaseAttribute = @"sampleBaseAttribute", 8 | }; 9 | 10 | @implementation AbstractRelatedEntityID 11 | @end 12 | 13 | @implementation _AbstractRelatedEntity 14 | 15 | + (id)insertInManagedObjectContext:(NSManagedObjectContext*)moc_ { 16 | NSParameterAssert(moc_); 17 | return [NSEntityDescription insertNewObjectForEntityForName:@"AbstractRelatedEntity" inManagedObjectContext:moc_]; 18 | } 19 | 20 | + (NSString*)entityName { 21 | return @"AbstractRelatedEntity"; 22 | } 23 | 24 | + (NSEntityDescription*)entityInManagedObjectContext:(NSManagedObjectContext*)moc_ { 25 | NSParameterAssert(moc_); 26 | return [NSEntityDescription entityForName:@"AbstractRelatedEntity" inManagedObjectContext:moc_]; 27 | } 28 | 29 | - (AbstractRelatedEntityID*)objectID { 30 | return (AbstractRelatedEntityID*)[super objectID]; 31 | } 32 | 33 | @dynamic sampleBaseAttribute; 34 | 35 | @end 36 | 37 | -------------------------------------------------------------------------------- /Tests/Fixtures/TestModel/_ConcreteRelatedEntity.h: -------------------------------------------------------------------------------- 1 | // DO NOT EDIT. This file is machine-generated and constantly overwritten. 2 | // Make changes to ConcreteRelatedEntity.h instead. 3 | 4 | #import 5 | #import "AbstractRelatedEntity.h" 6 | 7 | extern const struct ConcreteRelatedEntityAttributes { 8 | __unsafe_unretained NSString *sampleConcreteAttribute; 9 | } ConcreteRelatedEntityAttributes; 10 | 11 | @interface ConcreteRelatedEntityID : AbstractRelatedEntityID {} 12 | @end 13 | 14 | @interface _ConcreteRelatedEntity : AbstractRelatedEntity {} 15 | + (id)insertInManagedObjectContext:(NSManagedObjectContext*)moc_; 16 | + (NSString*)entityName; 17 | + (NSEntityDescription*)entityInManagedObjectContext:(NSManagedObjectContext*)moc_; 18 | - (ConcreteRelatedEntityID*)objectID; 19 | 20 | @property (nonatomic, strong) NSString* sampleConcreteAttribute; 21 | 22 | //- (BOOL)validateSampleConcreteAttribute:(id*)value_ error:(NSError**)error_; 23 | 24 | @end 25 | 26 | @interface _ConcreteRelatedEntity (CoreDataGeneratedPrimitiveAccessors) 27 | 28 | - (NSString*)primitiveSampleConcreteAttribute; 29 | - (void)setPrimitiveSampleConcreteAttribute:(NSString*)value; 30 | 31 | @end 32 | -------------------------------------------------------------------------------- /Tests/Fixtures/TestModel/_ConcreteRelatedEntity.m: -------------------------------------------------------------------------------- 1 | // DO NOT EDIT. This file is machine-generated and constantly overwritten. 2 | // Make changes to ConcreteRelatedEntity.m instead. 3 | 4 | #import "_ConcreteRelatedEntity.h" 5 | 6 | const struct ConcreteRelatedEntityAttributes ConcreteRelatedEntityAttributes = { 7 | .sampleConcreteAttribute = @"sampleConcreteAttribute", 8 | }; 9 | 10 | @implementation ConcreteRelatedEntityID 11 | @end 12 | 13 | @implementation _ConcreteRelatedEntity 14 | 15 | + (id)insertInManagedObjectContext:(NSManagedObjectContext*)moc_ { 16 | NSParameterAssert(moc_); 17 | return [NSEntityDescription insertNewObjectForEntityForName:@"ConcreteRelatedEntity" inManagedObjectContext:moc_]; 18 | } 19 | 20 | + (NSString*)entityName { 21 | return @"ConcreteRelatedEntity"; 22 | } 23 | 24 | + (NSEntityDescription*)entityInManagedObjectContext:(NSManagedObjectContext*)moc_ { 25 | NSParameterAssert(moc_); 26 | return [NSEntityDescription entityForName:@"ConcreteRelatedEntity" inManagedObjectContext:moc_]; 27 | } 28 | 29 | - (ConcreteRelatedEntityID*)objectID { 30 | return (ConcreteRelatedEntityID*)[super objectID]; 31 | } 32 | 33 | @dynamic sampleConcreteAttribute; 34 | 35 | @end 36 | 37 | -------------------------------------------------------------------------------- /Tests/Fixtures/TestModel/_DifferentClassNameMapping.h: -------------------------------------------------------------------------------- 1 | // DO NOT EDIT. This file is machine-generated and constantly overwritten. 2 | // Make changes to DifferentClassNameMapping.h instead. 3 | 4 | #import 5 | 6 | @interface DifferentClassNameMappingID : NSManagedObjectID {} 7 | @end 8 | 9 | @interface _DifferentClassNameMapping : NSManagedObject {} 10 | + (id)insertInManagedObjectContext:(NSManagedObjectContext*)moc_; 11 | + (NSString*)entityName; 12 | + (NSEntityDescription*)entityInManagedObjectContext:(NSManagedObjectContext*)moc_; 13 | - (DifferentClassNameMappingID*)objectID; 14 | 15 | @end 16 | 17 | @interface _DifferentClassNameMapping (CoreDataGeneratedPrimitiveAccessors) 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /Tests/Fixtures/TestModel/_DifferentClassNameMapping.m: -------------------------------------------------------------------------------- 1 | // DO NOT EDIT. This file is machine-generated and constantly overwritten. 2 | // Make changes to DifferentClassNameMapping.m instead. 3 | 4 | #import "_DifferentClassNameMapping.h" 5 | 6 | @implementation DifferentClassNameMappingID 7 | @end 8 | 9 | @implementation _DifferentClassNameMapping 10 | 11 | + (id)insertInManagedObjectContext:(NSManagedObjectContext*)moc_ { 12 | NSParameterAssert(moc_); 13 | return [NSEntityDescription insertNewObjectForEntityForName:@"EntityWithDifferentClassName" inManagedObjectContext:moc_]; 14 | } 15 | 16 | + (NSString*)entityName { 17 | return @"EntityWithDifferentClassName"; 18 | } 19 | 20 | + (NSEntityDescription*)entityInManagedObjectContext:(NSManagedObjectContext*)moc_ { 21 | NSParameterAssert(moc_); 22 | return [NSEntityDescription entityForName:@"EntityWithDifferentClassName" inManagedObjectContext:moc_]; 23 | } 24 | 25 | - (DifferentClassNameMappingID*)objectID { 26 | return (DifferentClassNameMappingID*)[super objectID]; 27 | } 28 | 29 | @end 30 | 31 | -------------------------------------------------------------------------------- /Tests/Fixtures/TestModel/_MappedEntity.h: -------------------------------------------------------------------------------- 1 | // DO NOT EDIT. This file is machine-generated and constantly overwritten. 2 | // Make changes to MappedEntity.h instead. 3 | 4 | #import 5 | 6 | extern const struct MappedEntityAttributes { 7 | __unsafe_unretained NSString *mappedEntityID; 8 | __unsafe_unretained NSString *nestedAttribute; 9 | __unsafe_unretained NSString *sampleAttribute; 10 | __unsafe_unretained NSString *testMappedEntityID; 11 | } MappedEntityAttributes; 12 | 13 | extern const struct MappedEntityUserInfo { 14 | __unsafe_unretained NSString *relatedByAttribute; 15 | } MappedEntityUserInfo; 16 | 17 | @interface MappedEntityID : NSManagedObjectID {} 18 | @end 19 | 20 | @interface _MappedEntity : NSManagedObject {} 21 | + (id)insertInManagedObjectContext:(NSManagedObjectContext*)moc_; 22 | + (NSString*)entityName; 23 | + (NSEntityDescription*)entityInManagedObjectContext:(NSManagedObjectContext*)moc_; 24 | - (MappedEntityID*)objectID; 25 | 26 | @property (nonatomic, strong) NSNumber* mappedEntityID; 27 | 28 | //- (BOOL)validateMappedEntityID:(id*)value_ error:(NSError**)error_; 29 | 30 | @property (nonatomic, strong) NSString* nestedAttribute; 31 | 32 | //- (BOOL)validateNestedAttribute:(id*)value_ error:(NSError**)error_; 33 | 34 | @property (nonatomic, strong) NSString* sampleAttribute; 35 | 36 | //- (BOOL)validateSampleAttribute:(id*)value_ error:(NSError**)error_; 37 | 38 | @property (nonatomic, strong) NSNumber* testMappedEntityID; 39 | 40 | //- (BOOL)validateTestMappedEntityID:(id*)value_ error:(NSError**)error_; 41 | 42 | @end 43 | 44 | @interface _MappedEntity (CoreDataGeneratedPrimitiveAccessors) 45 | 46 | - (NSNumber*)primitiveMappedEntityID; 47 | - (void)setPrimitiveMappedEntityID:(NSNumber*)value; 48 | 49 | - (NSString*)primitiveNestedAttribute; 50 | - (void)setPrimitiveNestedAttribute:(NSString*)value; 51 | 52 | - (NSString*)primitiveSampleAttribute; 53 | - (void)setPrimitiveSampleAttribute:(NSString*)value; 54 | 55 | - (NSNumber*)primitiveTestMappedEntityID; 56 | - (void)setPrimitiveTestMappedEntityID:(NSNumber*)value; 57 | 58 | @end 59 | -------------------------------------------------------------------------------- /Tests/Fixtures/TestModel/_MappedEntity.m: -------------------------------------------------------------------------------- 1 | // DO NOT EDIT. This file is machine-generated and constantly overwritten. 2 | // Make changes to MappedEntity.m instead. 3 | 4 | #import "_MappedEntity.h" 5 | 6 | const struct MappedEntityAttributes MappedEntityAttributes = { 7 | .mappedEntityID = @"mappedEntityID", 8 | .nestedAttribute = @"nestedAttribute", 9 | .sampleAttribute = @"sampleAttribute", 10 | .testMappedEntityID = @"testMappedEntityID", 11 | }; 12 | 13 | const struct MappedEntityUserInfo MappedEntityUserInfo = { 14 | .relatedByAttribute = @"mapped", 15 | }; 16 | 17 | @implementation MappedEntityID 18 | @end 19 | 20 | @implementation _MappedEntity 21 | 22 | + (id)insertInManagedObjectContext:(NSManagedObjectContext*)moc_ { 23 | NSParameterAssert(moc_); 24 | return [NSEntityDescription insertNewObjectForEntityForName:@"MappedEntity" inManagedObjectContext:moc_]; 25 | } 26 | 27 | + (NSString*)entityName { 28 | return @"MappedEntity"; 29 | } 30 | 31 | + (NSEntityDescription*)entityInManagedObjectContext:(NSManagedObjectContext*)moc_ { 32 | NSParameterAssert(moc_); 33 | return [NSEntityDescription entityForName:@"MappedEntity" inManagedObjectContext:moc_]; 34 | } 35 | 36 | - (MappedEntityID*)objectID { 37 | return (MappedEntityID*)[super objectID]; 38 | } 39 | 40 | @dynamic mappedEntityID; 41 | 42 | @dynamic nestedAttribute; 43 | 44 | @dynamic sampleAttribute; 45 | 46 | @dynamic testMappedEntityID; 47 | 48 | @end 49 | 50 | -------------------------------------------------------------------------------- /Tests/Fixtures/TestModel/_SingleEntityRelatedToManyMappedEntitiesUsingMappedPrimaryKey.h: -------------------------------------------------------------------------------- 1 | // DO NOT EDIT. This file is machine-generated and constantly overwritten. 2 | // Make changes to SingleEntityRelatedToManyMappedEntitiesUsingMappedPrimaryKey.h instead. 3 | 4 | #import 5 | 6 | extern const struct SingleEntityRelatedToManyMappedEntitiesUsingMappedPrimaryKeyAttributes { 7 | __unsafe_unretained NSString *testPrimaryKey; 8 | } SingleEntityRelatedToManyMappedEntitiesUsingMappedPrimaryKeyAttributes; 9 | 10 | extern const struct SingleEntityRelatedToManyMappedEntitiesUsingMappedPrimaryKeyRelationships { 11 | __unsafe_unretained NSString *mappedEntities; 12 | } SingleEntityRelatedToManyMappedEntitiesUsingMappedPrimaryKeyRelationships; 13 | 14 | extern const struct SingleEntityRelatedToManyMappedEntitiesUsingMappedPrimaryKeyUserInfo { 15 | __unsafe_unretained NSString *relatedByAttribute; 16 | } SingleEntityRelatedToManyMappedEntitiesUsingMappedPrimaryKeyUserInfo; 17 | 18 | @class MappedEntity; 19 | 20 | @interface SingleEntityRelatedToManyMappedEntitiesUsingMappedPrimaryKeyID : NSManagedObjectID {} 21 | @end 22 | 23 | @interface _SingleEntityRelatedToManyMappedEntitiesUsingMappedPrimaryKey : NSManagedObject {} 24 | + (id)insertInManagedObjectContext:(NSManagedObjectContext*)moc_; 25 | + (NSString*)entityName; 26 | + (NSEntityDescription*)entityInManagedObjectContext:(NSManagedObjectContext*)moc_; 27 | - (SingleEntityRelatedToManyMappedEntitiesUsingMappedPrimaryKeyID*)objectID; 28 | 29 | @property (nonatomic, strong) NSNumber* testPrimaryKey; 30 | 31 | //- (BOOL)validateTestPrimaryKey:(id*)value_ error:(NSError**)error_; 32 | 33 | @property (nonatomic, strong) NSSet *mappedEntities; 34 | 35 | - (NSMutableSet*)mappedEntitiesSet; 36 | 37 | @end 38 | 39 | @interface _SingleEntityRelatedToManyMappedEntitiesUsingMappedPrimaryKey (MappedEntitiesCoreDataGeneratedAccessors) 40 | - (void)addMappedEntities:(NSSet*)value_; 41 | - (void)removeMappedEntities:(NSSet*)value_; 42 | - (void)addMappedEntitiesObject:(MappedEntity*)value_; 43 | - (void)removeMappedEntitiesObject:(MappedEntity*)value_; 44 | @end 45 | 46 | @interface _SingleEntityRelatedToManyMappedEntitiesUsingMappedPrimaryKey (CoreDataGeneratedPrimitiveAccessors) 47 | 48 | - (NSNumber*)primitiveTestPrimaryKey; 49 | - (void)setPrimitiveTestPrimaryKey:(NSNumber*)value; 50 | 51 | - (NSMutableSet*)primitiveMappedEntities; 52 | - (void)setPrimitiveMappedEntities:(NSMutableSet*)value; 53 | 54 | @end 55 | -------------------------------------------------------------------------------- /Tests/Fixtures/TestModel/_SingleEntityRelatedToManyMappedEntitiesUsingMappedPrimaryKey.m: -------------------------------------------------------------------------------- 1 | // DO NOT EDIT. This file is machine-generated and constantly overwritten. 2 | // Make changes to SingleEntityRelatedToManyMappedEntitiesUsingMappedPrimaryKey.m instead. 3 | 4 | #import "_SingleEntityRelatedToManyMappedEntitiesUsingMappedPrimaryKey.h" 5 | 6 | const struct SingleEntityRelatedToManyMappedEntitiesUsingMappedPrimaryKeyAttributes SingleEntityRelatedToManyMappedEntitiesUsingMappedPrimaryKeyAttributes = { 7 | .testPrimaryKey = @"testPrimaryKey", 8 | }; 9 | 10 | const struct SingleEntityRelatedToManyMappedEntitiesUsingMappedPrimaryKeyRelationships SingleEntityRelatedToManyMappedEntitiesUsingMappedPrimaryKeyRelationships = { 11 | .mappedEntities = @"mappedEntities", 12 | }; 13 | 14 | const struct SingleEntityRelatedToManyMappedEntitiesUsingMappedPrimaryKeyUserInfo SingleEntityRelatedToManyMappedEntitiesUsingMappedPrimaryKeyUserInfo = { 15 | .relatedByAttribute = @"testPrimaryKey", 16 | }; 17 | 18 | @implementation SingleEntityRelatedToManyMappedEntitiesUsingMappedPrimaryKeyID 19 | @end 20 | 21 | @implementation _SingleEntityRelatedToManyMappedEntitiesUsingMappedPrimaryKey 22 | 23 | + (id)insertInManagedObjectContext:(NSManagedObjectContext*)moc_ { 24 | NSParameterAssert(moc_); 25 | return [NSEntityDescription insertNewObjectForEntityForName:@"SingleEntityRelatedToManyMappedEntitiesUsingMappedPrimaryKey" inManagedObjectContext:moc_]; 26 | } 27 | 28 | + (NSString*)entityName { 29 | return @"SingleEntityRelatedToManyMappedEntitiesUsingMappedPrimaryKey"; 30 | } 31 | 32 | + (NSEntityDescription*)entityInManagedObjectContext:(NSManagedObjectContext*)moc_ { 33 | NSParameterAssert(moc_); 34 | return [NSEntityDescription entityForName:@"SingleEntityRelatedToManyMappedEntitiesUsingMappedPrimaryKey" inManagedObjectContext:moc_]; 35 | } 36 | 37 | - (SingleEntityRelatedToManyMappedEntitiesUsingMappedPrimaryKeyID*)objectID { 38 | return (SingleEntityRelatedToManyMappedEntitiesUsingMappedPrimaryKeyID*)[super objectID]; 39 | } 40 | 41 | @dynamic testPrimaryKey; 42 | 43 | @dynamic mappedEntities; 44 | 45 | - (NSMutableSet*)mappedEntitiesSet { 46 | [self willAccessValueForKey:@"mappedEntities"]; 47 | 48 | NSMutableSet *result = (NSMutableSet*)[self mutableSetValueForKey:@"mappedEntities"]; 49 | 50 | [self didAccessValueForKey:@"mappedEntities"]; 51 | return result; 52 | } 53 | 54 | @end 55 | 56 | -------------------------------------------------------------------------------- /Tests/Fixtures/TestModel/_SingleEntityRelatedToMappedEntityUsingDefaults.h: -------------------------------------------------------------------------------- 1 | // DO NOT EDIT. This file is machine-generated and constantly overwritten. 2 | // Make changes to SingleEntityRelatedToMappedEntityUsingDefaults.h instead. 3 | 4 | #import 5 | 6 | extern const struct SingleEntityRelatedToMappedEntityUsingDefaultsAttributes { 7 | __unsafe_unretained NSString *singleEntityRelatedToMappedEntityUsingDefaultsID; 8 | } SingleEntityRelatedToMappedEntityUsingDefaultsAttributes; 9 | 10 | extern const struct SingleEntityRelatedToMappedEntityUsingDefaultsRelationships { 11 | __unsafe_unretained NSString *mappedEntity; 12 | } SingleEntityRelatedToMappedEntityUsingDefaultsRelationships; 13 | 14 | @class MappedEntity; 15 | 16 | @interface SingleEntityRelatedToMappedEntityUsingDefaultsID : NSManagedObjectID {} 17 | @end 18 | 19 | @interface _SingleEntityRelatedToMappedEntityUsingDefaults : NSManagedObject {} 20 | + (id)insertInManagedObjectContext:(NSManagedObjectContext*)moc_; 21 | + (NSString*)entityName; 22 | + (NSEntityDescription*)entityInManagedObjectContext:(NSManagedObjectContext*)moc_; 23 | - (SingleEntityRelatedToMappedEntityUsingDefaultsID*)objectID; 24 | 25 | @property (nonatomic, strong) NSNumber* singleEntityRelatedToMappedEntityUsingDefaultsID; 26 | 27 | //- (BOOL)validateSingleEntityRelatedToMappedEntityUsingDefaultsID:(id*)value_ error:(NSError**)error_; 28 | 29 | @property (nonatomic, strong) MappedEntity *mappedEntity; 30 | 31 | //- (BOOL)validateMappedEntity:(id*)value_ error:(NSError**)error_; 32 | 33 | @end 34 | 35 | @interface _SingleEntityRelatedToMappedEntityUsingDefaults (CoreDataGeneratedPrimitiveAccessors) 36 | 37 | - (NSNumber*)primitiveSingleEntityRelatedToMappedEntityUsingDefaultsID; 38 | - (void)setPrimitiveSingleEntityRelatedToMappedEntityUsingDefaultsID:(NSNumber*)value; 39 | 40 | - (MappedEntity*)primitiveMappedEntity; 41 | - (void)setPrimitiveMappedEntity:(MappedEntity*)value; 42 | 43 | @end 44 | -------------------------------------------------------------------------------- /Tests/Fixtures/TestModel/_SingleEntityRelatedToMappedEntityUsingDefaults.m: -------------------------------------------------------------------------------- 1 | // DO NOT EDIT. This file is machine-generated and constantly overwritten. 2 | // Make changes to SingleEntityRelatedToMappedEntityUsingDefaults.m instead. 3 | 4 | #import "_SingleEntityRelatedToMappedEntityUsingDefaults.h" 5 | 6 | const struct SingleEntityRelatedToMappedEntityUsingDefaultsAttributes SingleEntityRelatedToMappedEntityUsingDefaultsAttributes = { 7 | .singleEntityRelatedToMappedEntityUsingDefaultsID = @"singleEntityRelatedToMappedEntityUsingDefaultsID", 8 | }; 9 | 10 | const struct SingleEntityRelatedToMappedEntityUsingDefaultsRelationships SingleEntityRelatedToMappedEntityUsingDefaultsRelationships = { 11 | .mappedEntity = @"mappedEntity", 12 | }; 13 | 14 | @implementation SingleEntityRelatedToMappedEntityUsingDefaultsID 15 | @end 16 | 17 | @implementation _SingleEntityRelatedToMappedEntityUsingDefaults 18 | 19 | + (id)insertInManagedObjectContext:(NSManagedObjectContext*)moc_ { 20 | NSParameterAssert(moc_); 21 | return [NSEntityDescription insertNewObjectForEntityForName:@"SingleEntityRelatedToMappedEntityUsingDefaults" inManagedObjectContext:moc_]; 22 | } 23 | 24 | + (NSString*)entityName { 25 | return @"SingleEntityRelatedToMappedEntityUsingDefaults"; 26 | } 27 | 28 | + (NSEntityDescription*)entityInManagedObjectContext:(NSManagedObjectContext*)moc_ { 29 | NSParameterAssert(moc_); 30 | return [NSEntityDescription entityForName:@"SingleEntityRelatedToMappedEntityUsingDefaults" inManagedObjectContext:moc_]; 31 | } 32 | 33 | - (SingleEntityRelatedToMappedEntityUsingDefaultsID*)objectID { 34 | return (SingleEntityRelatedToMappedEntityUsingDefaultsID*)[super objectID]; 35 | } 36 | 37 | @dynamic singleEntityRelatedToMappedEntityUsingDefaultsID; 38 | 39 | @dynamic mappedEntity; 40 | 41 | @end 42 | 43 | -------------------------------------------------------------------------------- /Tests/Fixtures/TestModel/_SingleEntityRelatedToMappedEntityUsingMappedPrimaryKey.h: -------------------------------------------------------------------------------- 1 | // DO NOT EDIT. This file is machine-generated and constantly overwritten. 2 | // Make changes to SingleEntityRelatedToMappedEntityUsingMappedPrimaryKey.h instead. 3 | 4 | #import 5 | 6 | extern const struct SingleEntityRelatedToMappedEntityUsingMappedPrimaryKeyRelationships { 7 | __unsafe_unretained NSString *mappedEntity; 8 | } SingleEntityRelatedToMappedEntityUsingMappedPrimaryKeyRelationships; 9 | 10 | @class MappedEntity; 11 | 12 | @interface SingleEntityRelatedToMappedEntityUsingMappedPrimaryKeyID : NSManagedObjectID {} 13 | @end 14 | 15 | @interface _SingleEntityRelatedToMappedEntityUsingMappedPrimaryKey : NSManagedObject {} 16 | + (id)insertInManagedObjectContext:(NSManagedObjectContext*)moc_; 17 | + (NSString*)entityName; 18 | + (NSEntityDescription*)entityInManagedObjectContext:(NSManagedObjectContext*)moc_; 19 | - (SingleEntityRelatedToMappedEntityUsingMappedPrimaryKeyID*)objectID; 20 | 21 | @property (nonatomic, strong) MappedEntity *mappedEntity; 22 | 23 | //- (BOOL)validateMappedEntity:(id*)value_ error:(NSError**)error_; 24 | 25 | @end 26 | 27 | @interface _SingleEntityRelatedToMappedEntityUsingMappedPrimaryKey (CoreDataGeneratedPrimitiveAccessors) 28 | 29 | - (MappedEntity*)primitiveMappedEntity; 30 | - (void)setPrimitiveMappedEntity:(MappedEntity*)value; 31 | 32 | @end 33 | -------------------------------------------------------------------------------- /Tests/Fixtures/TestModel/_SingleEntityRelatedToMappedEntityUsingMappedPrimaryKey.m: -------------------------------------------------------------------------------- 1 | // DO NOT EDIT. This file is machine-generated and constantly overwritten. 2 | // Make changes to SingleEntityRelatedToMappedEntityUsingMappedPrimaryKey.m instead. 3 | 4 | #import "_SingleEntityRelatedToMappedEntityUsingMappedPrimaryKey.h" 5 | 6 | const struct SingleEntityRelatedToMappedEntityUsingMappedPrimaryKeyRelationships SingleEntityRelatedToMappedEntityUsingMappedPrimaryKeyRelationships = { 7 | .mappedEntity = @"mappedEntity", 8 | }; 9 | 10 | @implementation SingleEntityRelatedToMappedEntityUsingMappedPrimaryKeyID 11 | @end 12 | 13 | @implementation _SingleEntityRelatedToMappedEntityUsingMappedPrimaryKey 14 | 15 | + (id)insertInManagedObjectContext:(NSManagedObjectContext*)moc_ { 16 | NSParameterAssert(moc_); 17 | return [NSEntityDescription insertNewObjectForEntityForName:@"SingleEntityRelatedToMappedEntityUsingMappedPrimaryKey" inManagedObjectContext:moc_]; 18 | } 19 | 20 | + (NSString*)entityName { 21 | return @"SingleEntityRelatedToMappedEntityUsingMappedPrimaryKey"; 22 | } 23 | 24 | + (NSEntityDescription*)entityInManagedObjectContext:(NSManagedObjectContext*)moc_ { 25 | NSParameterAssert(moc_); 26 | return [NSEntityDescription entityForName:@"SingleEntityRelatedToMappedEntityUsingMappedPrimaryKey" inManagedObjectContext:moc_]; 27 | } 28 | 29 | - (SingleEntityRelatedToMappedEntityUsingMappedPrimaryKeyID*)objectID { 30 | return (SingleEntityRelatedToMappedEntityUsingMappedPrimaryKeyID*)[super objectID]; 31 | } 32 | 33 | @dynamic mappedEntity; 34 | 35 | @end 36 | 37 | -------------------------------------------------------------------------------- /Tests/Fixtures/TestModel/_SingleEntityRelatedToMappedEntityWithNestedMappedAttributes.h: -------------------------------------------------------------------------------- 1 | // DO NOT EDIT. This file is machine-generated and constantly overwritten. 2 | // Make changes to SingleEntityRelatedToMappedEntityWithNestedMappedAttributes.h instead. 3 | 4 | #import 5 | 6 | extern const struct SingleEntityRelatedToMappedEntityWithNestedMappedAttributesRelationships { 7 | __unsafe_unretained NSString *mappedEntity; 8 | } SingleEntityRelatedToMappedEntityWithNestedMappedAttributesRelationships; 9 | 10 | @class MappedEntity; 11 | 12 | @interface SingleEntityRelatedToMappedEntityWithNestedMappedAttributesID : NSManagedObjectID {} 13 | @end 14 | 15 | @interface _SingleEntityRelatedToMappedEntityWithNestedMappedAttributes : NSManagedObject {} 16 | + (id)insertInManagedObjectContext:(NSManagedObjectContext*)moc_; 17 | + (NSString*)entityName; 18 | + (NSEntityDescription*)entityInManagedObjectContext:(NSManagedObjectContext*)moc_; 19 | - (SingleEntityRelatedToMappedEntityWithNestedMappedAttributesID*)objectID; 20 | 21 | @property (nonatomic, strong) MappedEntity *mappedEntity; 22 | 23 | //- (BOOL)validateMappedEntity:(id*)value_ error:(NSError**)error_; 24 | 25 | @end 26 | 27 | @interface _SingleEntityRelatedToMappedEntityWithNestedMappedAttributes (CoreDataGeneratedPrimitiveAccessors) 28 | 29 | - (MappedEntity*)primitiveMappedEntity; 30 | - (void)setPrimitiveMappedEntity:(MappedEntity*)value; 31 | 32 | @end 33 | -------------------------------------------------------------------------------- /Tests/Fixtures/TestModel/_SingleEntityRelatedToMappedEntityWithNestedMappedAttributes.m: -------------------------------------------------------------------------------- 1 | // DO NOT EDIT. This file is machine-generated and constantly overwritten. 2 | // Make changes to SingleEntityRelatedToMappedEntityWithNestedMappedAttributes.m instead. 3 | 4 | #import "_SingleEntityRelatedToMappedEntityWithNestedMappedAttributes.h" 5 | 6 | const struct SingleEntityRelatedToMappedEntityWithNestedMappedAttributesRelationships SingleEntityRelatedToMappedEntityWithNestedMappedAttributesRelationships = { 7 | .mappedEntity = @"mappedEntity", 8 | }; 9 | 10 | @implementation SingleEntityRelatedToMappedEntityWithNestedMappedAttributesID 11 | @end 12 | 13 | @implementation _SingleEntityRelatedToMappedEntityWithNestedMappedAttributes 14 | 15 | + (id)insertInManagedObjectContext:(NSManagedObjectContext*)moc_ { 16 | NSParameterAssert(moc_); 17 | return [NSEntityDescription insertNewObjectForEntityForName:@"SingleEntityRelatedToMappedEntityWithNestedMappedAttributes" inManagedObjectContext:moc_]; 18 | } 19 | 20 | + (NSString*)entityName { 21 | return @"SingleEntityRelatedToMappedEntityWithNestedMappedAttributes"; 22 | } 23 | 24 | + (NSEntityDescription*)entityInManagedObjectContext:(NSManagedObjectContext*)moc_ { 25 | NSParameterAssert(moc_); 26 | return [NSEntityDescription entityForName:@"SingleEntityRelatedToMappedEntityWithNestedMappedAttributes" inManagedObjectContext:moc_]; 27 | } 28 | 29 | - (SingleEntityRelatedToMappedEntityWithNestedMappedAttributesID*)objectID { 30 | return (SingleEntityRelatedToMappedEntityWithNestedMappedAttributesID*)[super objectID]; 31 | } 32 | 33 | @dynamic mappedEntity; 34 | 35 | @end 36 | 37 | -------------------------------------------------------------------------------- /Tests/Fixtures/TestModel/_SingleEntityRelatedToMappedEntityWithSecondaryMappings.h: -------------------------------------------------------------------------------- 1 | // DO NOT EDIT. This file is machine-generated and constantly overwritten. 2 | // Make changes to SingleEntityRelatedToMappedEntityWithSecondaryMappings.h instead. 3 | 4 | #import 5 | 6 | extern const struct SingleEntityRelatedToMappedEntityWithSecondaryMappingsAttributes { 7 | __unsafe_unretained NSString *secondaryMappedAttribute; 8 | __unsafe_unretained NSString *notImportedAttribute; 9 | } SingleEntityRelatedToMappedEntityWithSecondaryMappingsAttributes; 10 | 11 | extern const struct SingleEntityRelatedToMappedEntityWithSecondaryMappingsRelationships { 12 | __unsafe_unretained NSString *mappedRelationship; 13 | } SingleEntityRelatedToMappedEntityWithSecondaryMappingsRelationships; 14 | 15 | @class MappedEntity; 16 | 17 | @interface SingleEntityRelatedToMappedEntityWithSecondaryMappingsID : NSManagedObjectID {} 18 | @end 19 | 20 | @interface _SingleEntityRelatedToMappedEntityWithSecondaryMappings : NSManagedObject {} 21 | + (id)insertInManagedObjectContext:(NSManagedObjectContext*)moc_; 22 | + (NSString*)entityName; 23 | + (NSEntityDescription*)entityInManagedObjectContext:(NSManagedObjectContext*)moc_; 24 | - (SingleEntityRelatedToMappedEntityWithSecondaryMappingsID*)objectID; 25 | 26 | @property (nonatomic, strong) NSString* secondaryMappedAttribute; 27 | 28 | //- (BOOL)validateSecondaryMappedAttribute:(id*)value_ error:(NSError**)error_; 29 | 30 | @property (nonatomic, strong) NSNumber *notImportedAttribute; 31 | 32 | //- (BOOL)validateNotImportedAttribute:(id*)value_ error:(NSError**)error_; 33 | 34 | @property (nonatomic, strong) MappedEntity *mappedRelationship; 35 | 36 | //- (BOOL)validateMappedRelationship:(id*)value_ error:(NSError**)error_; 37 | 38 | @end 39 | 40 | @interface _SingleEntityRelatedToMappedEntityWithSecondaryMappings (CoreDataGeneratedPrimitiveAccessors) 41 | 42 | - (NSNumber*)primitiveNotImportedAttribute; 43 | - (void)setPrimitiveNotImportedAttribute:(NSNumber*)value; 44 | 45 | - (NSString*)primitiveSecondaryMappedAttribute; 46 | - (void)setPrimitiveSecondaryMappedAttribute:(NSString*)value; 47 | 48 | - (MappedEntity*)primitiveMappedRelationship; 49 | - (void)setPrimitiveMappedRelationship:(MappedEntity*)value; 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /Tests/Fixtures/TestModel/_SingleEntityRelatedToMappedEntityWithSecondaryMappings.m: -------------------------------------------------------------------------------- 1 | // DO NOT EDIT. This file is machine-generated and constantly overwritten. 2 | // Make changes to SingleEntityRelatedToMappedEntityWithSecondaryMappings.m instead. 3 | 4 | #import "_SingleEntityRelatedToMappedEntityWithSecondaryMappings.h" 5 | 6 | const struct SingleEntityRelatedToMappedEntityWithSecondaryMappingsAttributes SingleEntityRelatedToMappedEntityWithSecondaryMappingsAttributes = { 7 | .secondaryMappedAttribute = @"secondaryMappedAttribute", 8 | .notImportedAttribute = @"notImportedAttribute", 9 | }; 10 | 11 | const struct SingleEntityRelatedToMappedEntityWithSecondaryMappingsRelationships SingleEntityRelatedToMappedEntityWithSecondaryMappingsRelationships = { 12 | .mappedRelationship = @"mappedRelationship", 13 | }; 14 | 15 | @implementation SingleEntityRelatedToMappedEntityWithSecondaryMappingsID 16 | @end 17 | 18 | @implementation _SingleEntityRelatedToMappedEntityWithSecondaryMappings 19 | 20 | + (id)insertInManagedObjectContext:(NSManagedObjectContext*)moc_ { 21 | NSParameterAssert(moc_); 22 | return [NSEntityDescription insertNewObjectForEntityForName:@"SingleEntityRelatedToMappedEntityWithSecondaryMappings" inManagedObjectContext:moc_]; 23 | } 24 | 25 | + (NSString*)entityName { 26 | return @"SingleEntityRelatedToMappedEntityWithSecondaryMappings"; 27 | } 28 | 29 | + (NSEntityDescription*)entityInManagedObjectContext:(NSManagedObjectContext*)moc_ { 30 | NSParameterAssert(moc_); 31 | return [NSEntityDescription entityForName:@"SingleEntityRelatedToMappedEntityWithSecondaryMappings" inManagedObjectContext:moc_]; 32 | } 33 | 34 | - (SingleEntityRelatedToMappedEntityWithSecondaryMappingsID*)objectID { 35 | return (SingleEntityRelatedToMappedEntityWithSecondaryMappingsID*)[super objectID]; 36 | } 37 | 38 | - (id)valueForUndefinedKey:(NSString *)key 39 | { 40 | if ([key isEqualToString:@"secondaryMappedAttribute"]) 41 | { 42 | return self.secondaryMappedAttribute; 43 | } 44 | else if ([key isEqualToString:@"notImportedAttribute"]) 45 | { 46 | return self.notImportedAttribute; 47 | } 48 | 49 | return nil; 50 | } 51 | 52 | @dynamic secondaryMappedAttribute; 53 | 54 | @dynamic notImportedAttribute; 55 | 56 | @dynamic mappedRelationship; 57 | 58 | @end 59 | 60 | -------------------------------------------------------------------------------- /Tests/Fixtures/TestModel/_SingleEntityWithNoRelationships.m: -------------------------------------------------------------------------------- 1 | // DO NOT EDIT. This file is machine-generated and constantly overwritten. 2 | // Make changes to SingleEntityWithNoRelationships.m instead. 3 | 4 | #import "_SingleEntityWithNoRelationships.h" 5 | 6 | const struct SingleEntityWithNoRelationshipsAttributes SingleEntityWithNoRelationshipsAttributes = { 7 | .booleanAsStringTestAttribute = @"booleanAsStringTestAttribute", 8 | .booleanTestAttribute = @"booleanTestAttribute", 9 | .colorTestAttribute = @"colorTestAttribute", 10 | .dateTestAttribute = @"dateTestAttribute", 11 | .dateWithCustomFormat = @"dateWithCustomFormat", 12 | .decimalTestAttribute = @"decimalTestAttribute", 13 | .doubleTestAttribute = @"doubleTestAttribute", 14 | .floatTestAttribute = @"floatTestAttribute", 15 | .int16TestAttribute = @"int16TestAttribute", 16 | .int32TestAttribute = @"int32TestAttribute", 17 | .int64TestAttribute = @"int64TestAttribute", 18 | .mappedStringAttribute = @"mappedStringAttribute", 19 | .notInJsonAttribute = @"notInJsonAttribute", 20 | .nullTestAttribute = @"nullTestAttribute", 21 | .numberAsStringTestAttribute = @"numberAsStringTestAttribute", 22 | .stringTestAttribute = @"stringTestAttribute", 23 | .unixTime13TestAttribute = @"unixTime13TestAttribute", 24 | .unixTimeTestAttribute = @"unixTimeTestAttribute", 25 | }; 26 | 27 | @implementation SingleEntityWithNoRelationshipsID 28 | @end 29 | 30 | @implementation _SingleEntityWithNoRelationships 31 | 32 | + (id)insertInManagedObjectContext:(NSManagedObjectContext*)moc_ { 33 | NSParameterAssert(moc_); 34 | return [NSEntityDescription insertNewObjectForEntityForName:@"SingleEntityWithNoRelationships" inManagedObjectContext:moc_]; 35 | } 36 | 37 | + (NSString*)entityName { 38 | return @"SingleEntityWithNoRelationships"; 39 | } 40 | 41 | + (NSEntityDescription*)entityInManagedObjectContext:(NSManagedObjectContext*)moc_ { 42 | NSParameterAssert(moc_); 43 | return [NSEntityDescription entityForName:@"SingleEntityWithNoRelationships" inManagedObjectContext:moc_]; 44 | } 45 | 46 | - (SingleEntityWithNoRelationshipsID*)objectID { 47 | return (SingleEntityWithNoRelationshipsID*)[super objectID]; 48 | } 49 | 50 | @dynamic booleanAsStringTestAttribute; 51 | 52 | @dynamic booleanTestAttribute; 53 | 54 | @dynamic colorTestAttribute; 55 | 56 | @dynamic dateTestAttribute; 57 | 58 | @dynamic dateWithCustomFormat; 59 | 60 | @dynamic decimalTestAttribute; 61 | 62 | @dynamic doubleTestAttribute; 63 | 64 | @dynamic floatTestAttribute; 65 | 66 | @dynamic int16TestAttribute; 67 | 68 | @dynamic int32TestAttribute; 69 | 70 | @dynamic int64TestAttribute; 71 | 72 | @dynamic mappedStringAttribute; 73 | 74 | @dynamic notInJsonAttribute; 75 | 76 | @dynamic nullTestAttribute; 77 | 78 | @dynamic numberAsStringTestAttribute; 79 | 80 | @dynamic stringTestAttribute; 81 | 82 | @dynamic unixTime13TestAttribute; 83 | 84 | @dynamic unixTimeTestAttribute; 85 | 86 | @end 87 | 88 | -------------------------------------------------------------------------------- /Tests/Fixtures/TestModel/_SingleRelatedEntity.m: -------------------------------------------------------------------------------- 1 | // DO NOT EDIT. This file is machine-generated and constantly overwritten. 2 | // Make changes to SingleRelatedEntity.m instead. 3 | 4 | #import "_SingleRelatedEntity.h" 5 | 6 | const struct SingleRelatedEntityAttributes SingleRelatedEntityAttributes = { 7 | .mappedStringAttribute = @"mappedStringAttribute", 8 | }; 9 | 10 | const struct SingleRelatedEntityRelationships SingleRelatedEntityRelationships = { 11 | .testAbstractToManyRelationship = @"testAbstractToManyRelationship", 12 | .testAbstractToOneRelationship = @"testAbstractToOneRelationship", 13 | .testConcreteToManyRelationship = @"testConcreteToManyRelationship", 14 | .testConcreteToOneRelationship = @"testConcreteToOneRelationship", 15 | }; 16 | 17 | @implementation SingleRelatedEntityID 18 | @end 19 | 20 | @implementation _SingleRelatedEntity 21 | 22 | + (id)insertInManagedObjectContext:(NSManagedObjectContext*)moc_ { 23 | NSParameterAssert(moc_); 24 | return [NSEntityDescription insertNewObjectForEntityForName:@"SingleRelatedEntity" inManagedObjectContext:moc_]; 25 | } 26 | 27 | + (NSString*)entityName { 28 | return @"SingleRelatedEntity"; 29 | } 30 | 31 | + (NSEntityDescription*)entityInManagedObjectContext:(NSManagedObjectContext*)moc_ { 32 | NSParameterAssert(moc_); 33 | return [NSEntityDescription entityForName:@"SingleRelatedEntity" inManagedObjectContext:moc_]; 34 | } 35 | 36 | - (SingleRelatedEntityID*)objectID { 37 | return (SingleRelatedEntityID*)[super objectID]; 38 | } 39 | 40 | @dynamic mappedStringAttribute; 41 | 42 | @dynamic testAbstractToManyRelationship; 43 | 44 | - (NSMutableSet*)testAbstractToManyRelationshipSet { 45 | [self willAccessValueForKey:@"testAbstractToManyRelationship"]; 46 | 47 | NSMutableSet *result = (NSMutableSet*)[self mutableSetValueForKey:@"testAbstractToManyRelationship"]; 48 | 49 | [self didAccessValueForKey:@"testAbstractToManyRelationship"]; 50 | return result; 51 | } 52 | 53 | @dynamic testAbstractToOneRelationship; 54 | 55 | @dynamic testConcreteToManyRelationship; 56 | 57 | - (NSMutableSet*)testConcreteToManyRelationshipSet { 58 | [self willAccessValueForKey:@"testConcreteToManyRelationship"]; 59 | 60 | NSMutableSet *result = (NSMutableSet*)[self mutableSetValueForKey:@"testConcreteToManyRelationship"]; 61 | 62 | [self didAccessValueForKey:@"testConcreteToManyRelationship"]; 63 | return result; 64 | } 65 | 66 | @dynamic testConcreteToOneRelationship; 67 | 68 | @end 69 | 70 | -------------------------------------------------------------------------------- /Tests/Support/MagicalRecordTestHelpers.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2015 Magical Panda Software LLC. All rights reserved. 3 | 4 | #import 5 | 6 | @interface MagicalRecordTestHelpers : NSObject 7 | 8 | + (BOOL)removeStoreFilesForStoreAtURL:(NSURL *)storeURL; 9 | 10 | @end 11 | -------------------------------------------------------------------------------- /Tests/Support/MagicalRecordTestHelpers.m: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2015 Magical Panda Software LLC. All rights reserved. 3 | 4 | #import "MagicalRecordTestHelpers.h" 5 | 6 | @implementation MagicalRecordTestHelpers 7 | 8 | + (BOOL)removeStoreFilesForStoreAtURL:(NSURL *)storeURL 9 | { 10 | NSString *rawURL = [storeURL absoluteString]; 11 | NSURL *shmSidecar = [NSURL URLWithString:[rawURL stringByAppendingString:@"-shm"]]; 12 | NSURL *walSidecar = [NSURL URLWithString:[rawURL stringByAppendingString:@"-wal"]]; 13 | 14 | BOOL success = YES; 15 | success &= [[NSFileManager defaultManager] removeItemAtURL:storeURL error:nil]; 16 | success &= [[NSFileManager defaultManager] removeItemAtURL:shmSidecar error:nil]; 17 | success &= [[NSFileManager defaultManager] removeItemAtURL:walSidecar error:nil]; 18 | 19 | return success; 20 | } 21 | 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /Tests/Support/MagicalRecordTests-OSX-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundlePackageType 14 | BNDL 15 | CFBundleShortVersionString 16 | 1.0 17 | CFBundleSignature 18 | ???? 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /Tests/Support/MagicalRecordTests-OSX-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'MagicalRecordTests' target in the 'MagicalRecordTests' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #import "MagicalRecord.h" 8 | #endif 9 | -------------------------------------------------------------------------------- /Tests/Support/MagicalRecordTests-iOS-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundlePackageType 14 | BNDL 15 | CFBundleShortVersionString 16 | 1.0 17 | CFBundleSignature 18 | ???? 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /Tests/Support/MagicalRecordTests-iOS-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'MagicalRecordTests' target in the 'MagicalRecordTests' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #import 8 | #import 9 | #endif 10 | -------------------------------------------------------------------------------- /Tests/Support/MagicalRecordTests-tvOS-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | --------------------------------------------------------------------------------