Skip to content

Commit f185e3a

Browse files
committed
updated README.md
1 parent 1ab18ae commit f185e3a

File tree

1 file changed

+61
-5
lines changed

1 file changed

+61
-5
lines changed

README.md

Lines changed: 61 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ for example, if you have following JSON
150150
]
151151
}
152152
}
153-
154153
```
154+
155155
which translates to following objects.
156156

157157
```objective-c
@@ -169,8 +169,6 @@ which translates to following objects.
169169
@property(nonatomic, strong) NSString *modelType;
170170

171171
@end
172-
173-
174172
```
175173

176174
you can convert json like this:
@@ -183,12 +181,70 @@ MyObject *myObject = [MyObject objectWithDictionary:dictionary mapping:mappingDi
183181

184182
```
185183
184+
##SHRealmObject
185+
186+
Realm support out of the box. `SHRealmObject` is a sublclass of `RLMObject` from Realm. If you want to use both SHModelObject to parse your JSON responses and have RLMObject to be used with Realm database. `SHRealmObject` is they class you need.
187+
188+
`SHRealmObject` is identical in functionality as `SHModelObject` but also confirms with `RLMObject`. that means the it also confirms with the restriction that `RLMObject` class has. (e.g. you cannot use `NSDictionary` objects. and instead of using `NSArrays` you will use `RLMArray<T>` objects).
189+
190+
`RLMArray<T>` objects will also be parsed automatically for you based on the mapping dictionary provided. (check out parsing arrays section above)
191+
192+
Following is a simple example.
193+
194+
195+
```objective-c
196+
@interface Person : SHRealmObject
197+
198+
@property NSString *name;
199+
@property int age;
200+
@property RLMArray<Car> *cars;
201+
202+
@end
203+
204+
@implementation Person
205+
@end
206+
207+
////
208+
209+
@interface Car : SHRealmObject
210+
@property NSString *model;
211+
@end
212+
213+
@implementation Car
214+
@end
215+
```
216+
217+
and to add an object in Realm database.
218+
219+
```objective-c
220+
RLMRealm *realm = [RLMRealm defaultRealm];
221+
[realm transactionWithBlock:^{
222+
NSDictionary *d = @{
223+
@"nAme" : @"Shan Ul Haq",
224+
@"_AGE" : @26,
225+
@"cars" : @[ @{@"moDEL" : @"Honda"}, @{@"model" : @"Toyota"} ]
226+
};
227+
Person *p = [Person objectWithDictionary:d mappings:@{ @"cars" : @"Car" }];
228+
[realm addObject:p];
229+
}];
230+
```
231+
186232
187233
##How to Use it.
188234
189-
1- Add the classes into your project
235+
1- add the files
236+
237+
**Using Cocoapods**
238+
239+
- add `pod 'SHModelObject/Core'` in your Podfile if you just want to use `SHModelObject`
240+
- add `pod 'SHModelObject/Realm'` in your Podfile if you want to use `SHRealmObject` with Realm.
241+
- add `pod 'SHModelObject'` in your Podfile if you want to use both `SHModelObject` and `SHRealmObject`.
242+
243+
**Manual**
244+
245+
- Just add the classes into your project.
190246
191-
2- sublcass your models with `SHModelObject`
247+
2- sublcass your models with `SHModelObject` or `SHRealmObject`
192248
193249
3- initialize using the povided initializers and pass the response NSDictionary ( initWithDictionary: and other variants )
194250

0 commit comments

Comments
 (0)