Ios-runtime-is pushed to any controller based on the class name and implements the property pass value

Source: Internet
Author: User

////WJRUNTIME.M//Runtimeskip////Created by Tqh on 15/9/8.//Copyright (c) 2015 TQH. All rights reserved.//#import "WJRuntime.h"#import<objc/runtime.h>@implementationWjruntime//Runtime Jump+ (void) Runtimepush: (NSString *) vcname dic: (nsdictionary *) DiC nav: (Uinavigationcontroller *) Nav {//class name (object name)NSString*class=Vcname; Const Char*classname = [classcstringusingencoding:nsasciistringencoding]; Class Newclass=Objc_getclass (className); if(!Newclass) {        //Create a classClass superclass = [NSObjectclass]; Newclass= Objc_allocateclasspair (superclass, ClassName,0); //register the class that you createdObjc_registerclasspair (Newclass); }    //Create the object (write here can be random page jump)    IDInstance =[[Newclass alloc] init]; //here is the value--------------[dic enumeratekeysandobjectsusingblock:^(IDKeyIDobj, BOOL *stop) {        if([self checkisexistpropertywithinstance:instance verifypropertyname:key]) {//KVC Assigning a value to a property[instance setvalue:obj Forkey:key]; }Else{NSLog (@"properties that do not contain key=%@", key);    }    }];    [Nav pushviewcontroller:instance Animated:yes]; }/** * Detects if the object has this attribute*/+ (BOOL) Checkisexistpropertywithinstance: (ID) Instance Verifypropertyname: (NSString *) verifypropertyname{unsignedintOutcount, I; //gets the list of properties in the objectobjc_property_t * Properties =Class_copypropertylist ([instanceclass], &outcount);  for(i =0; i < Outcount; i++) {objc_property_t property=Properties[i]; //property names into stringsNSString *propertyname =[[NSString alloc] Initwithcstring:property_getname (property) encoding:nsutf8stringencoding]; //determine if the property exists        if([PropertyName isequaltostring:verifypropertyname]) {free (properties); returnYES;        }} free (properties); returnNO;}@end

Ios-runtime-is pushed to any controller based on the class name and implements the property pass value

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.