iOS Development Project-25 dictionary to model Introduction to third-party frameworks and runtime mechanisms
First, using a third-party framework to complete the dictionary to model
1. Get the framework
In the www.code4app.com Web site, search the dictionary to model
You can download it by clicking the download code, or you can take github to download it.
Benefits of the Management framework: Clicking the Refresh button refreshes all items.
2. Use
1. Import a third-party framework
2. Using the example
Error message:
Use a single line of code when you refresh:
1 /** Load up-to- date Weibo data*/2-(void) Loadnewstatus3 {4 //1. Obtaining the Request Manager5Afhttprequestoperationmanager *mgr =[Afhttprequestoperationmanager manager];6 7 //2. Package Request Parameters8 9Nsmutabledictionary *params=[Nsmutabledictionary dictionary];Ten params[@"Access_token"] =[Yyaccounttool Accountmodel].access_token; One //set Request returns 3 days of data A params[@"Count"][email protected] A; - - the //3. Send a POST request - //URL:Https://api.weibo.com/2/statuses/home_timeline.json -[Mgr GET:@"Https://api.weibo.com/2/statuses/home_timeline.json"Parametersparamssuccess:^ (afhttprequestoperation *operation, nsdictionary*accountdict) { - +Yylog (@"Request succeeded--%@", accountdict[@"statuses"]); - //self.statuses=accountdict[@ "statuses"]; + ASelf.statuses =[Nsmutablearray array]; at - //Weibo dictionary--arrays -Nsarray *statusdictarray = accountdict[@"statuses"]; - - //Weibo Dictionary Array---"Weibo model array -self.statuses=[Yystatusmodel Objectarraywithkeyvaluesarray:statusdictarray]; in - //For (nsdictionary *statusdict in Statusdictarray) { to //Yystatusmodel *status = [Yystatusmodel objectwithkeyvalues:statusdict]; + //[self.statuses addobject:status]; - // } the // * $ //re-refresh the tablePanax Notoginseng [Self.tableview Reloaddata]; -} failure:^ (Afhttprequestoperation *operation, Nserror *error) { theYylog (@"request failed"); + }]; A the}
Tells the array that the model is stored:
1 //2 //YYSTATUSMODEL.M3 //4 5 #import "YYStatusModel.h"6 #import "MJExtension.h"7 #import "YYPhotoModel.h"8 9 @implementationYystatusmodelTen //+ (Instancetype) statusmodelwithdict: (Nsdictionary *) Dict One //{ A //Yystatusmodel *model=[[self Alloc]init]; - //model.text=dict[@ "text"]; - // the //model.user=[yyusermodel usermodelwithdict:dict[@ "user"]; - // - // //Nested Models - //nsdictionary *retweeteddict = dict[@ "Retweeteddict"]; + //if (retweeteddict) { - //Model.retweeted_status=[yystatusmodel statusmodelwithdict:retweeteddict]; + // } A //return model; at //} - --(Nsdictionary *) Objectclassinarray - { - return@{@"Pic_urls": [Yyphotomodelclass]}; - } in - @end
Effect:
Ii. introduction of the operation
Runtime: Actually is the bottom of OC, usually write the OC code, eventually converted to the bottom of the runtime code (pure C language)
View the generated files
The converted main function:
Remove the code after the cast:
Note : Understanding the message mechanism
The compiler converts all of the OC code we write into runtime code, and the code above translates to sending messages
OC is a C language that wears an object-oriented cloak.
The runtime emphasizes the ability to dynamically modify, delete methods, and so on.