Recently, looking at Mjextension's demo, we found a method for plist file to go directly to the array model. Previously studied but did not solve the problem, these days have time, a good look, found a solution to share with you.
If you have a plist file with this nested array object in your project, such as:
That is to be converted into an object where another array of objects is stored.
When there is no such complex nesting, we write:
1: -(Nsarray *) groups{
2: if (!_groups) {
3:
4: _groups = [Group objectarraywithfilename:@ "Cars_total.plist"];
5: }
6: return _groups;
7: }
In this case, however, the cars attribute in groups is assigned a "Nsarray with nsdictionary" variable instead of "Nsarray with car class"
And there's no real turning into a model, and at first my solution was to rewrite the Setcars method,
//-(void) Setcars: (Nsarray *) cars{//// NSLog (@ "%s", __func__); // _cars = [Nsmutablearray array]; // _cars = [Car modelarraywithdictionaries:cars]; //}
Modelarraywithdictionaries is my own implementation of a dictionary array to an array of methods, the writing is not elegant is not posted out.
But we can actually write this:
Writing one:
In the group model
1: //+ (nsdictionary *) objectclassinarray{
2: // return @{@ "Cars": @ "Car"};
3: //}
Two:
In the getter of the Groups property
1: (Nsarray *) groups{
2: if (!_groups) {
3:
4: [Group setupobjectclassinarray:^nsdictionary *{
5: return @{@ "Cars":@ "Car"};
6: }];
7: _groups = [Group objectarraywithfilename:@ "Cars_total.plist"];
8: }
9: return _groups;
Ten: }
can be converted directly to the object!
Other findings in Mjextension Demo:
Mjextension's demo will [x Setupobjectclassinarray: ...] Put it in the mjextensionconfig.
In the +load method of the class, there is no reference to the class or method elsewhere in the demo.
After the query, found that the original load is OC in the loading of a class when the method is automatically called, is a good way to configure!
Reference Source:
Objective-c class Methods The difference between load and initialize
IOS mjextension Framework Dictionary array to model array
Codermjlee/mjextension
iOS Development--mjextension Complex array usage