{"id":13437909,"url":"https://github.com/SSheldon/rust-objc","last_synced_at":"2025-03-19T18:31:07.404Z","repository":{"id":40280989,"uuid":"20874187","full_name":"SSheldon/rust-objc","owner":"SSheldon","description":"Objective-C Runtime bindings and wrapper for Rust.","archived":false,"fork":false,"pushed_at":"2024-06-04T14:09:59.000Z","size":7200,"stargazers_count":394,"open_issues_count":39,"forks_count":59,"subscribers_count":17,"default_branch":"master","last_synced_at":"2025-03-16T20:08:37.251Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://crates.io/crates/objc","language":"Rust","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/SSheldon.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","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":"2014-06-16T05:52:03.000Z","updated_at":"2025-03-14T14:02:51.000Z","dependencies_parsed_at":"2024-06-18T15:29:21.063Z","dependency_job_id":"d3ee8465-ba31-43ed-ac7f-a060df4f0b1b","html_url":"https://github.com/SSheldon/rust-objc","commit_stats":{"total_commits":630,"total_committers":11,"mean_commits":57.27272727272727,"dds":0.01904761904761909,"last_synced_commit":"c8696b0cd1932fdf1b5b22c03af86f32a934f42f"},"previous_names":[],"tags_count":25,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SSheldon%2Frust-objc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SSheldon%2Frust-objc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SSheldon%2Frust-objc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SSheldon%2Frust-objc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SSheldon","download_url":"https://codeload.github.com/SSheldon/rust-objc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244483201,"owners_count":20460074,"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":[],"created_at":"2024-07-31T03:01:01.150Z","updated_at":"2025-03-19T18:31:07.064Z","avatar_url":"https://github.com/SSheldon.png","language":"Rust","readme":"Objective-C Runtime bindings and wrapper for Rust.\n\n* Documentation: http://ssheldon.github.io/rust-objc/objc/\n* Crate: https://crates.io/crates/objc\n\n## Messaging objects\n\nObjective-C objects can be messaged using the `msg_send!` macro:\n\n``` rust\nlet cls = class!(NSObject);\nlet obj: *mut Object = msg_send![cls, new];\nlet hash: usize = msg_send![obj, hash];\nlet is_kind: BOOL = msg_send![obj, isKindOfClass:cls];\n// Even void methods must have their return type annotated\nlet _: () = msg_send![obj, release];\n```\n\n## Reference counting\n\nThe utilities of the `rc` module provide ARC-like semantics for working with\nObjective-C's reference counted objects in Rust.\nA `StrongPtr` retains an object and releases the object when dropped.\nA `WeakPtr` will not retain the object, but can be upgraded to a `StrongPtr`\nand safely fails if the object has been deallocated.\n\n``` rust\n// StrongPtr will release the object when dropped\nlet obj = unsafe {\n    StrongPtr::new(msg_send![class!(NSObject), new])\n};\n\n// Cloning retains the object an additional time\nlet cloned = obj.clone();\nautoreleasepool(|| {\n    // Autorelease consumes the StrongPtr, but won't\n    // actually release until the end of an autoreleasepool\n    cloned.autorelease();\n});\n\n// Weak references won't retain the object\nlet weak = obj.weak();\ndrop(obj);\nassert!(weak.load().is_null());\n```\n\n## Declaring classes\n\nClasses can be declared using the `ClassDecl` struct. Instance variables and\nmethods can then be added before the class is ultimately registered.\n\nThe following example demonstrates declaring a class named `MyNumber` that has\none ivar, a `u32` named `_number` and a `number` method that returns it:\n\n``` rust\nlet superclass = class!(NSObject);\nlet mut decl = ClassDecl::new(\"MyNumber\", superclass).unwrap();\n\n// Add an instance variable\ndecl.add_ivar::\u003cu32\u003e(\"_number\");\n\n// Add an ObjC method for getting the number\nextern fn my_number_get(this: \u0026Object, _cmd: Sel) -\u003e u32 {\n    unsafe { *this.get_ivar(\"_number\") }\n}\nunsafe {\n    decl.add_method(sel!(number),\n        my_number_get as extern fn(\u0026Object, Sel) -\u003e u32);\n}\n\ndecl.register();\n```\n\n## Exceptions\n\nBy default, if the `msg_send!` macro causes an exception to be thrown, this\nwill unwind into Rust resulting in unsafe, undefined behavior.\nHowever, this crate has an `\"exception\"` feature which, when enabled, wraps\neach `msg_send!` in a `@try`/`@catch` and panics if an exception is caught,\npreventing Objective-C from unwinding into Rust.\n\n## Message type verification\n\nThe Objective-C runtime includes encodings for each method that describe the\nargument and return types. This crate can take advantage of these encodings to\nverify that the types used in Rust match the types encoded for the method.\n\nTo use this functionality, enable the `\"verify_message\"` feature.\nWith this feature enabled, type checking is performed for every message send,\nwhich also requires that all arguments and return values for all messages\nimplement `Encode`.\n\nIf this requirement is burdensome or you'd rather just verify specific messages,\nyou can call the `Message::verify_message` method for specific selectors.\n\n## Support for other Operating Systems\n\nThe bindings can be used on Linux or *BSD utilizing the\n[GNUstep Objective-C runtime](https://www.github.com/gnustep/libobjc2).\n","funding_links":[],"categories":["Development tools","开发工具 Development tools","Rust","开发工具"],"sub_categories":["FFI","FFI FFI","示例 FFI"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSSheldon%2Frust-objc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FSSheldon%2Frust-objc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSSheldon%2Frust-objc/lists"}