{"id":3033,"url":"https://github.com/marmelroy/ObjectiveKit","last_synced_at":"2025-08-06T16:31:58.533Z","repository":{"id":56921181,"uuid":"73640355","full_name":"marmelroy/ObjectiveKit","owner":"marmelroy","description":"Swift-friendly API for a set of powerful Objective C runtime functions.","archived":false,"fork":false,"pushed_at":"2020-06-22T01:49:21.000Z","size":47,"stargazers_count":849,"open_issues_count":5,"forks_count":36,"subscribers_count":14,"default_branch":"master","last_synced_at":"2024-12-05T18:11:53.889Z","etag":null,"topics":["introspect","runtime","swift"],"latest_commit_sha":null,"homepage":"","language":"Swift","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/marmelroy.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":"2016-11-13T20:16:31.000Z","updated_at":"2024-11-02T04:43:25.000Z","dependencies_parsed_at":"2022-08-20T21:50:33.375Z","dependency_job_id":null,"html_url":"https://github.com/marmelroy/ObjectiveKit","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marmelroy%2FObjectiveKit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marmelroy%2FObjectiveKit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marmelroy%2FObjectiveKit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marmelroy%2FObjectiveKit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/marmelroy","download_url":"https://codeload.github.com/marmelroy/ObjectiveKit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228923746,"owners_count":17992573,"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","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":["introspect","runtime","swift"],"created_at":"2024-01-05T20:16:29.500Z","updated_at":"2024-12-09T16:31:16.349Z","avatar_url":"https://github.com/marmelroy.png","language":"Swift","readme":"![ObjectiveKit - Swift friendly ObjC-Runtime functions ](https://cloud.githubusercontent.com/assets/889949/20305900/0e2db7c8-ab38-11e6-8aea-3556c34bfd21.png)\n\n[![Build Status](https://travis-ci.org/marmelroy/ObjectiveKit.svg?branch=master)](https://travis-ci.org/marmelroy/ObjectiveKit)\n[![Version](http://img.shields.io/cocoapods/v/ObjectiveKit.svg)](http://cocoapods.org/?q=ObjectiveKit)\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n\n# ObjectiveKit\nObjectiveKit provides a Swift friendly API for a set of powerful Objective C runtime functions.\n\n## Usage\n\nTo use ObjectiveKit:\n\nImport ObjectiveKit at the top of your Swift file:\n```swift\nimport ObjectiveKit\n```\n\nThe next step is to create an ObjectiveClass object typed for the class you want to modify or introspect:\n```swift\nlet viewClass = ObjectiveClass\u003cUIView\u003e()\n```\n\nIf using ObjectiveKit on a custom Swift class, make sure that it inherits at some point from NSObject and that it is exposed to the Objective C runtime using the @objc flag.\n\n### Introspection\n\nYou can learn more about classes at runtime with these handy introspection methods:\n```swift\nlet mapViewClass = ObjectiveClass\u003cMKMapView\u003e()\nlet ivars = mapViewClass.ivars // An array of ivars.\nlet selectors = mapViewClass.selectors // An array of selectors.\nlet properties = mapViewClass.properties // An array of properties.\nlet protocols = mapViewClass.protocols // An array of protocols.\n```\n\n### Modifying classes at runtime\n\nAdd a pre-existing selector from another class to your ObjectiveClass:\n```swift\nlet viewClass = ObjectiveClass\u003cUIView\u003e()\nviewClass.addSelector(#selector(testSelector), from: self.classForCoder)\nlet view = UIView()\nview.perform(#selector(testSelector))\n```\n\nAdd a custom method by providing the implementation with a closure:\n```swift\nlet viewClass = ObjectiveClass\u003cUIView\u003e()\nviewClass.addMethod(closureName, implementation: {\n    print(\"hello world\")\n})\nlet view = UIView()\nview.performMethod(closureName)\n```\n\nObjectiveKit also supports exchanging selectors in the same class:\n```swift\nlet viewClass = ObjectiveClass\u003cUIView\u003e()\nviewClass.exchangeSelector(#selector(UIView.layoutSubviews), with: #selector(UIView.xxx_layoutSubviews))\n```\n\n### Creating classes at runtime\n\nLastly, you can also create a custom ObjC class at runtime:\n```swift\nlet runtimeClass = RuntimeClass(superclass: UIView.self)\nruntimeClass.addIvar(ivarName, type: .Float)\nlet runtimeObject = runtimeClass.allocate()\nruntimeObject.setValue(4.0, forKey: ivarName)\n```\n\n## Setting up\n\n### Setting up with [CocoaPods](http://cocoapods.org/?q=ObjectiveKit)\n```ruby\nsource 'https://github.com/CocoaPods/Specs.git'\npod 'ObjectiveKit', '~\u003e 0.2'\n```\n\n### Setting up with Carthage\n\n[Carthage](https://github.com/Carthage/Carthage) is a decentralized dependency manager that automates the process of adding frameworks to your Cocoa application.\n\nYou can install Carthage with [Homebrew](http://brew.sh/) using the following command:\n\n```bash\n$ brew update\n$ brew install carthage\n```\n\nTo integrate ObjectiveKit into your Xcode project using Carthage, specify it in your `Cartfile`:\n\n```ogdl\ngithub \"marmelroy/ObjectiveKit\"\n```\n\n### Inspiration\n- [https://github.com/mikeash/MAObjCRuntime](https://github.com/mikeash/MAObjCRuntime)\n","funding_links":[],"categories":["Utility","Libs","Utility [🔝](#readme)"],"sub_categories":["Web View","Utility","Other free courses"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarmelroy%2FObjectiveKit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarmelroy%2FObjectiveKit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarmelroy%2FObjectiveKit/lists"}