-
Notifications
You must be signed in to change notification settings - Fork 395
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #68 from tyrone-sudeium/master
PONSO: NSSet-based templates, improved inverse relationship logic
- Loading branch information
Showing
54 changed files
with
3,840 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
PONSO - Plain Old NSObjects | ||
=========================== | ||
|
||
What is PONSO? | ||
-------------- | ||
The idea is to use mogenerator to generate lightweight, memory-only, type-safe ObjC data model classes from Xcode data models. | ||
|
||
Features | ||
-------- | ||
- Type-safe attributes | ||
- Supports one-to-one and one-to-many relationships | ||
- Relationships are always ordered - implemented with NSArrays | ||
- Supports inverse relationships, which should be always marked as 'transient' | ||
- Supports serialization of any model object to NSDictionary and initialization from NSDictionary | ||
- Supports writing and reading to binary property list files | ||
- Requires that data model is a tree, where nodes are entities and edges are strong, non-transient relationships. Does not work with graph data models. | ||
- Supports weak relationships which are not archived in serialized form. These relationships are not considered as part of the object graph tree, e.g. you can have strong relationships A -> B, A -> C and a weak relationship B -> C and this won't invalidate the "tree model" requirement. | ||
- To create a weak relationship, add "destinationEntityIDKeyPath" user info key to that relationship in Xcode data modeller, and specify the name of attribute which can be used as unique ID to find the destination object. See sample projects entities DepartmentAssistant and DepartmentEmployee for examples. | ||
- Cycles between weak relationships are found automatically and are warned about during code generation. | ||
|
||
|
||
How to use | ||
---------- | ||
- The only additional source code you need to compile into your application for PONSO is ModelObject class found in "contributed templates/Nikita Zhuk/ponso/code" | ||
- See "contributed templates/Nikita Zhuk/ponso/sample project/PonsoTest" project for sample setup | ||
|
||
|
||
TODO | ||
----- | ||
PONSO is a work in progress and can be enchanced in a various ways. | ||
|
||
Some missing features include: | ||
- Automatic setting of inverse one-to-one relationships in setters | ||
- Support for many-to-many relationships | ||
- Implementations of to-many relationships as ordered sets instead of arrays | ||
- Detection of retain cycles caused by both relationship directions being non-transient | ||
|
||
Feel free to fork & contribute. | ||
|
||
|
||
Contact info | ||
------------- | ||
Nikita Zhuk, 2011 | ||
Twitter: @nzhuk | ||
|
58 changes: 58 additions & 0 deletions
58
contributed templates/Tyrone Trevorrow/ponso/code/ModelObject.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
Copyright 2011 Marko Karppinen & Co. LLC. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
ModelObject.h | ||
mogenerator / PONSO | ||
Created by Nikita Zhuk on 22.1.2011. | ||
*/ | ||
|
||
/** | ||
Abstract superclass for all of our model classes. | ||
*/ | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@interface ModelObject : NSObject <NSCopying, NSCoding> | ||
{ | ||
NSDictionary *sourceDictionaryRepresentation; | ||
} | ||
|
||
@property(nonatomic, retain) NSDictionary *sourceDictionaryRepresentation; | ||
|
||
/** | ||
Reads and deserializes a ModelObject from plist at given \c filePath | ||
\return Newly created ModelObject or nil if any of the following occurs: file doesn't exist, file cannot be read, plist cannot be parsed. | ||
*/ | ||
+ (id)createModelObjectFromFile:(NSString *)filePath; | ||
|
||
/** | ||
Serializes the receiver into binary plist and writes it to given \c filePath. Creates any intermediate directories in the path if necessary. | ||
\return YES on success, NO on error (binary serialization or I/O error). | ||
*/ | ||
- (BOOL)writeToFile:(NSString *)filePath; | ||
|
||
- (id)initWithDictionaryRepresentation:(NSDictionary *)dictionary; | ||
- (NSDictionary *)dictionaryRepresentation; | ||
|
||
- (void)awakeFromDictionaryRepresentationInit; | ||
|
||
@end | ||
|
||
|
||
@interface NSMutableDictionary (PONSONSMutableDictionaryAdditions) | ||
|
||
- (void)setObjectIfNotNil:(id)obj forKey:(NSString *)key; | ||
|
||
@end |
Oops, something went wrong.