{"id":28378418,"url":"https://github.com/rickytan/fixit","last_synced_at":"2025-07-23T14:08:12.631Z","repository":{"id":56910551,"uuid":"161146362","full_name":"rickytan/FIXiT","owner":"rickytan","description":"Yet another javascript fixing solution for Objective-C","archived":false,"fork":false,"pushed_at":"2020-07-16T12:45:24.000Z","size":76,"stargazers_count":8,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-26T21:40:22.546Z","etag":null,"topics":["aspect","bugfix","fixit","javascript","javascriptcore","js","objc","runtime"],"latest_commit_sha":null,"homepage":"","language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rickytan.png","metadata":{"files":{"readme":"README.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}},"created_at":"2018-12-10T09:00:31.000Z","updated_at":"2024-12-25T02:21:18.000Z","dependencies_parsed_at":"2022-08-20T19:50:35.112Z","dependency_job_id":null,"html_url":"https://github.com/rickytan/FIXiT","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/rickytan/FIXiT","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rickytan%2FFIXiT","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rickytan%2FFIXiT/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rickytan%2FFIXiT/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rickytan%2FFIXiT/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rickytan","download_url":"https://codeload.github.com/rickytan/FIXiT/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rickytan%2FFIXiT/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266691580,"owners_count":23969182,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-23T02:00:09.312Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"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":["aspect","bugfix","fixit","javascript","javascriptcore","js","objc","runtime"],"created_at":"2025-05-30T02:06:28.662Z","updated_at":"2025-07-23T14:08:12.607Z","avatar_url":"https://github.com/rickytan.png","language":"Objective-C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FIXiT\n\n[![CI Status](https://img.shields.io/travis/rickytan/FIXiT.svg?style=flat)](https://travis-ci.org/rickytan/FIXiT)\n[![Version](https://img.shields.io/cocoapods/v/FIXiT.svg?style=flat)](https://cocoapods.org/pods/FIXiT)\n[![License](https://img.shields.io/cocoapods/l/FIXiT.svg?style=flat)](https://cocoapods.org/pods/FIXiT)\n[![Platform](https://img.shields.io/cocoapods/p/FIXiT.svg?style=flat)](https://cocoapods.org/pods/FIXiT)\n\n## 简介\n此项目可以理解为 **JS** 版的 **[Aspect](https://github.com/steipete/Aspects)**\n\n## 用法示例（快速入手）\n### 修复已有方法的 Bug\nOC 中定义了类型：\n```objc\n\n@implementation NSObject (Crash)\n\n- (void)crashIt\n{\n  NSLog(@\"%@\", @[][1]);\n}\n\n- (CGPoint)locationOf:(NSArray \u003cNSValue *\u003e *)locations\n              atIndex:(NSInteger)index\n         defaultValue:(CGPoint)point\n{\n  return locations[index].CGPointValue;\n}\n\n@end\n```\n添加 JS 文件以修复：\n```javascript\nvar fix = Fixit.fix('NSObject');\nfix.instanceMethod('crashIt', function () {\n  \n});\n// fix.instanceMethod 返回原实现\nvar originMethod = fix.instanceMethod('locationOf:atIndex:defaultValue:', function (locations, index, point) {\n    // 此函数中的 this 就是 OC 的实例\n    if (index \u003c locations.length) {\n        return locations[index];    \n        // 或者调原实现 \n        return originMethod.apply(this, arguments);\n        // 等价于\n        return originMethod.call(this, locations, index, point);\n    }\n    return point;   // 这里的 point 会变为 NSValue，直接返回即可\n});\n```\n### 在原有实现上添加行为\n已有的 OC 类定义：\n```objc\n@implementation MyViewController\n{\n    UIButton    * _button;\n}\n\n- (void)viewDidLoad\n{\n    [super viewDidLoad];\n    ...\n}\n```\n添加 JS 文件以添加行为：\n```javascript\nrequire('UIAlertView, UIColor');\nvar fix = Fixit.fix('MyViewController');\nvar originViewDidLoad = fix.instanceMethod('viewDidLoad', function () {\n    // 先调原实现\n    originViewDidLoad.apply(this, arguments);\n    \n    this.view.backgroundColor = UIColor.yellowColor;\n    // 或者\n    this.view['setBackgroundColor:'](UIColor.yellowColor);\n    \n    // [] 取 JS 的属性或方法，当无参数时是属性，有参数时是方法\n    var button = this['_button'];   // 与 this._button 等价\n    // button 变量是 nil 安全的，当然也可以判断一下，使用 isNil 函数，\n    // 而不能 if (button == nil)，或者 if (button)。\n    // 所有不能转为 JS 对象的 OC 对象在 JS 代码中都是一个代理对象（Proxy）\n    if (!isNil(button)) {\n        // 调用时参数需要与 OC 中对应\n        button['setTitle:forState:']('test title', 0);\n    }\n    \n    // 创建一个弹窗，注意使用 nil，而不是 null\n    var that = this;\n    dispatch_after(2, function() {\n        // 注意 JS context 的变化，这里的 this 已经不是 MyViewController 了\n        UIAlertView.alloc['initWithTitle:message:delegate:cancelButtonTitle:otherButtonTitles:'](that.title, 'message!!!', nil, 'ok', nil).show();\n    });\n});\n```\n\n## Requirements\n\n* Xcode 9+\n* iOS 10+\n\n## Installation\n\nFIXiT is available through [CocoaPods](https://cocoapods.org). To install\nit, simply add the following line to your Podfile:\n\n```ruby\npod 'FIXiT'\n```\n\n## Author\n\nrickytan, ricky.tan.xin@gmail.com\n\n## License\n\nFIXIT is available under the MIT license. See the LICENSE file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frickytan%2Ffixit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frickytan%2Ffixit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frickytan%2Ffixit/lists"}