{"id":21373576,"url":"https://github.com/itenfay/dyfruntimeprovider","last_synced_at":"2026-02-14T07:01:48.266Z","repository":{"id":56908118,"uuid":"229787749","full_name":"itenfay/DYFRuntimeProvider","owner":"itenfay","description":"Wraps the runtime, and can quickly use for the transformation of the dictionary and model, archiving and unarchiving, adding a method, exchanging two methods, replacing a method, and getting all the variable names, property names and method names of a class.","archived":false,"fork":false,"pushed_at":"2024-06-22T16:11:35.000Z","size":167,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-01-04T06:30:50.514Z","etag":null,"topics":["ios","objc-runtime","objective-c","runtime","runtime-api","runtime-application","runtime-provider","runtime-wrapper"],"latest_commit_sha":null,"homepage":"","language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/itenfay.png","metadata":{"files":{"readme":"README-en.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-12-23T16:32:11.000Z","updated_at":"2024-06-22T16:10:08.000Z","dependencies_parsed_at":"2024-06-02T10:13:56.925Z","dependency_job_id":"b49e55ac-61d9-468b-818b-a90f7373436f","html_url":"https://github.com/itenfay/DYFRuntimeProvider","commit_stats":null,"previous_names":["itenfay/dyfruntimeprovider","chenxing640/dyfruntimeprovider"],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/itenfay/DYFRuntimeProvider","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itenfay%2FDYFRuntimeProvider","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itenfay%2FDYFRuntimeProvider/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itenfay%2FDYFRuntimeProvider/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itenfay%2FDYFRuntimeProvider/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/itenfay","download_url":"https://codeload.github.com/itenfay/DYFRuntimeProvider/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itenfay%2FDYFRuntimeProvider/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29438977,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-14T05:24:35.651Z","status":"ssl_error","status_checked_at":"2026-02-14T05:24:34.830Z","response_time":53,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ios","objc-runtime","objective-c","runtime","runtime-api","runtime-application","runtime-provider","runtime-wrapper"],"created_at":"2024-11-22T08:29:21.590Z","updated_at":"2026-02-14T07:01:48.248Z","avatar_url":"https://github.com/itenfay.png","language":"Objective-C","readme":"English Vision | [中文版](README.md)\n\n## DYFRuntimeProvider\n\n`DYFRuntimeProvider` wraps the runtime, and provides some common usages([Swift Version](https://github.com/itenfay/DYFSwiftRuntimeProvider)).\n\n[![License MIT](https://img.shields.io/badge/license-MIT-green.svg?style=flat)](LICENSE)\u0026nbsp;\n[![CocoaPods Version](http://img.shields.io/cocoapods/v/DYFRuntimeProvider.svg?style=flat)](http://cocoapods.org/pods/DYFRuntimeProvider)\u0026nbsp;\n![CocoaPods Platform](http://img.shields.io/cocoapods/p/DYFRuntimeProvider.svg?style=flat)\u0026nbsp;\n\n\n## Group (ID:614799921)\n\n\u003cdiv align=left\u003e\n\u0026emsp; \u003cimg src=\"https://github.com/itenfay/DYFRuntimeProvider/raw/master/images/g614799921.jpg\" width=\"30%\" /\u003e\n\u003c/div\u003e\n\n\n## Installation\n\nUsing [CocoaPods](https://cocoapods.org):\n\n\n``` \npod 'DYFRuntimeProvider'\n```\n\nOr\n\n```\npod 'DYFRuntimeProvider', '~\u003e 2.1.1'\n```\n\n\n## Usage\n\nAdd `#import \"DYFRuntimeProvider.h\"` to your source code.\n\n### Gets all the method names of a class\n\n**1. Gets all method names of an instance of a class**\n\n```\nNSArray *instMethods = [DYFRuntimeProvider getMethodListWithClass:UITableView.class];\nNSLog(@\"========instMethods: %@\", instMethods);\n```\n\n**2. Gets all class method names of a class**\n\n```\nNSArray *clsMethods = [DYFRuntimeProvider getClassMethodListWithClass:UIView.class];\nNSLog(@\"========clsMethods: %@\", clsMethods);\n```\n\n### Gets all variable names of a class\n\n```\nNSArray *ivars = [DYFRuntimeProvider getIvarListWithClass:UIButton.class];\nNSLog(@\"========ivars: %@\", ivars);\n```\n\n### Gets all the property names of a class\n\n```\nNSArray *properties = [DYFRuntimeProvider getPropertyListWithClass:UIButton.class];\nNSLog(@\"========properties: %@\", properties);\n```\n\nTake this class as an example. e.g.:\n\n```\n@interface Teacher : NSObject\n@property (nonatomic, assign) NSInteger age;\n@property (nonatomic, copy) NSString *name;\n@property (nonatomic, copy) NSString *address;\n\n- (void)eatWithFoods:(NSDictionary *)foods;\n- (void)runWithStep:(NSInteger)step;\n- (void)run2WithStep:(NSInteger)step;\n\n+ (void)decInfo:(NSString *)name age:(NSInteger)age;\n+ (void)decInfo2:(NSString *)name age:(NSInteger)age;\n\n@end\n\n@implementation Teacher\n\n- (void)eatWithFoods:(NSDictionary *)foods\n{\n    NSLog(@\"========%@ eat foods: %@\", _name, foods);\n}\n\n- (void)runWithStep:(NSInteger)step\n{\n    NSLog(@\"========%s 1 %@ runs %ld steps\", __func__, _name, step);\n}\n\n- (void)run2WithStep:(NSInteger)step\n{\n    NSLog(@\"========%s 2 %@ runs %ld steps\", __func__, _name, step);\n}\n\n+ (void)decInfo:(NSString *)name age:(NSInteger)age\n{\n    NSLog(@\"========decInfo name: %@, age: %ld\", name, age);\n}\n\n+ (void)decInfo2:(NSString *)name age:(NSInteger)age\n{\n    NSLog(@\"========decInfo2 name: %@, age: %ld\", name, age);\n}\n```\n\n### Adds a method\n\n```\nvoid rt_eatWithFoods2(id self, SEL _cmd, NSDictionary *foods)\n{\n    NSLog(@\"========%@, %@ eat foods: %@\", self, NSStringFromSelector(_cmd), foods);\n}\n\n- (void)viewDidLoad \n{\n    [super viewDidLoad];\n    SEL eatSel = NSSelectorFromString(@\"rt_eatWithFoods:\");\n    [DYFRuntimeProvider addMethodWithClass:Teacher.class selector:eatSel impSelector:@selector(eatWithFoods:)];\n    \n    SEL eatSel2 = NSSelectorFromString(@\"eatWithFoods2:\");\n    [DYFRuntimeProvider addMethodWithClass:Teacher.class selector:eatSel2 imp:(IMP)rt_eatWithFoods2 types:\"v@:@\"];\n    \n    Teacher *teacher = [[Teacher alloc] init];\n    #pragma clang diagnostic push\n    #pragma clang diagnostic ignored \"-Warc-performSelector-leaks\"\n    if ([teacher respondsToSelector:eatSel]) {\n        [teacher performSelector:eatSel withObject:@{@\"name\": @\"meat\", @\"number\": @1}];\n    }\n    \n    if ([teacher respondsToSelector:eatSel2]) {\n        [teacher performSelector:eatSel2 withObject:@{@\"name\": @\"meat\", @\"number\": @1}];\n    }\n    #pragma clang diagnostic pop\n}\n```\n\n### Exchanges two methods\n\n```\n- (void)viewDidLoad \n{\n    [super viewDidLoad];\n    [DYFRuntimeProvider exchangeMethodWithClass:Teacher.class selector:@selector(runWithStep:) anotherSelector:@selector(run2WithStep:)];\n    Teacher *teacher = [[Teacher alloc] init];\n    [teacher runWithStep:50];\n    [teacher run2WithStep:100];\n    \n    [DYFRuntimeProvider exchangeClassMethodWithClass:Teacher.class selector:@selector(decInfo:age:) anotherSelector:@selector(decInfo2:age:)];\n    [Teacher decInfo:@\"David\" age:40];\n    [Teacher decInfo2:@\"Liming\" age:28];\n}\n```\n\n### Replaces a method\n\n```\n- (void)viewDidLoad \n{\n    [super viewDidLoad];\n    [DYFRuntimeProvider replaceMethodWithClass:Teacher.class selector:@selector(runWithStep:) targetSelector:@selector(run2WithStep:)];\n    Teacher *teacher = [[Teacher alloc] init];\n    [teacher runWithStep:50];\n    [teacher run2WithStep:100];\n}\n```\n\n### Swizzle two methods\n\n```\n- (void)viewDidLoad \n{\n    [super viewDidLoad];\n    [DYFRuntimeProvider swizzleMethodWithClass:Teacher.class selector:@selector(runWithStep:) swizzledSelector:@selector(run2WithStep:)];\n    Teacher *teacher = [[Teacher alloc] init];\n    [teacher runWithStep:50];\n    [teacher run2WithStep:100];\n    \n    [DYFRuntimeProvider swizzleClassMethodWithClass:Teacher.class selector:@selector(decInfo:age:) swizzledSelector:@selector(decInfo2:age:)];\n    [Teacher decInfo:@\"David\" age:40];\n    [Teacher decInfo2:@\"Liming\" age:28];\n}\n```\n\n### The transformation of dictionary and model\n\n**1. Converts the dictionary to model**\n\n```\nTeacher *teacher = (Teacher *)[DYFRuntimeProvider asObjectWithDictionary:@{@\"name\": @\"高粟\", @\"age\": @26, @\"address\": @\"xx市xx\"} forClass:Teacher.class];\nif (teacher) {\n    NSLog(@\"========teacher: %@, %@, %ld, %@\", teacher, teacher.name, (long)teacher.age, teacher.address);\n}\n\nTeacher *teacher2 = [[Teacher alloc] init];\n[DYFRuntimeProvider asObjectWithDictionary:@{@\"name\": @\"高粟\", @\"age\": @26, @\"address\": @\"xx市xx\"} forObject:teacher2];\nNSLog(@\"========teacher2: %@, %@, %ld, %@\", teacher2, teacher2.name, (long)teacher2.age, teacher2.address);\n```\n\n**2. Converts the model to dictionary**\n\n```\nNSDictionary *dict = [DYFRuntimeProvider asDictionaryWithObject:teacher];\nNSLog(@\"========dict: %@\", dict);\n```\n\n### Archives and unarchives\n\nTake this class as an example. e.g.:\n\n```\n@interface Transaction : NSObject \u003cNSCoding\u003e\n@property (nonatomic, assign) NSUInteger state;\n@property (nonatomic, copy) NSString *productIdentifier;\n@property (nonatomic, copy) NSString *userIdentifier;\n@property (nonatomic, copy) NSString *originalTransactionTimestamp;\n@end\n\n@implementation Transaction\n\n- (instancetype)initWithCoder:(NSCoder *)aDecoder\n{\n    self = [super init];\n    if (self) {\n        [DYFRuntimeProvider decode:aDecoder forObject:self];\n    }\n    return self;\n}\n\n- (void)encodeWithCoder:(NSCoder *)aCoder\n {\n    [DYFRuntimeProvider encode:aCoder forObject:self];\n}\n\n@end\n```\n\n**1. Archives**\n\n```\n- (void)viewDidLoad \n{\n    [super viewDidLoad];\n    NSString *documentPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES) lastObject];\n    NSString *filePath = [documentPath stringByAppendingPathComponent:@\"Transaction.data\"];\n    [self archive:filePath];\n}\n\n- (void)archive:(NSString *)path \n{\n    Transaction *transaction = [[Transaction alloc] init];\n    [DYFRuntimeProvider archiveWithObject:transaction forClass:Transaction.class toFile:path];\n}\n```\n\nOr\n\n```\n@implementation Transaction\n\n- (void)encodeWithCoder:(NSCoder *)aCoder \n{\n    [DYFRuntimeProvider encode:aCoder forObject:self];\n}\n\n@end\n```\n\n**2. Unarchives**\n\n```\n- (void)viewDidLoad \n{\n    [super viewDidLoad];\n    NSString *documentPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES) lastObject];\n    NSString *filePath = [documentPath stringByAppendingPathComponent:@\"Transaction.data\"];\n    [self unarchive:filePath];\n}\n\n- (void)unarchive:(NSString *)path \n{\n    Transaction *transaction = [DYFRuntimeProvider unarchiveWithFile:path forClass:Transaction.class];\n}\n```\n\nOr\n\n```\n@implementation Transaction\n\n- (instancetype)initWithCoder:(NSCoder *)aDecoder\n{\n    self = [super init];\n    if (self) {\n        [DYFRuntimeProvider decode:aDecoder forObject:self];\n    }\n    return self;\n}\n\n@end\n```\n\n### Add a catogory property\n\n```\n@interface UIApplication (Pt)\n@property (nonatomic, strong) Teacher *teacher;\n@end\n\nstatic NSString *kTeacherKey = @\"TeacherKey\";\n\n@implementation UIApplication (Pt)\n\n- (Teacher *)teacher\n{\n    return (Teacher *)[DYFRuntimeProvider getAssociatedObject:self key:\u0026kTeacherKey];\n}\n\n- (void)setTeacher:(Teacher *)teacher\n{\n    [DYFRuntimeProvider setAssociatedObject:self key:\u0026kTeacherKey value:teacher policy:OBJC_ASSOCIATION_RETAIN_NONATOMIC];\n}\n\n@end\n```\n\n```\n- (void)viewDidLoad \n{\n    [super viewDidLoad];\n    Teacher *teacher2 = [[Teacher alloc] init];\n    [DYFRuntimeProvider asObjectWithDictionary:@{@\"name\": @\"高粟\", @\"age\": @26, @\"address\": @\"xx市xx\"} forObject:teacher2];\n    UIApplication.sharedApplication.teacher = teacher2;\n    NSLog(@\"========teacher: %@\", UIApplication.sharedApplication.teacher);\n}\n```\n\n\n### Get and modify instance variable property.\n\n```\nTeacher *teacher = (Teacher *)[DYFRuntimeProvider asObjectWithDictionary:@{@\"name\": @\"高粟\", @\"age\": @26, @\"address\": @\"xx市xx\"} forClass:Teacher.class];\nNSString *teacherName = [DYFRuntimeProvider getInstanceVarWithName:@\"_name\" forObject:teacher];\nNSLog(@\"========teacher name: %@\", teacherName);\n[DYFRuntimeProvider setInstanceVarWithName:@\"_name\" value:@\"李想\" forObject:teacher];\nNSLog(@\"========teacher newName: %@\", teacher.name);\n```\n\n\n## Demo\n\n`DYFRuntimeProvider` is learned how to use under this [Demo](https://github.com/itenfay/DYFSwiftRuntimeProvider/raw/master/Example/RuntimeExample).\n\n\n## Feedback is welcome\n\nIf you notice any issue to create an issue. I will be happy to help you.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitenfay%2Fdyfruntimeprovider","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fitenfay%2Fdyfruntimeprovider","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitenfay%2Fdyfruntimeprovider/lists"}