{"id":16209171,"url":"https://github.com/gilzoide/unity-objectivec","last_synced_at":"2025-04-10T10:21:07.076Z","repository":{"id":70590846,"uuid":"552082286","full_name":"gilzoide/unity-objectivec","owner":"gilzoide","description":"High level C# to Objective-C interface, similar to Unity's AndroidJavaClass and AndroidJavaObject","archived":false,"fork":false,"pushed_at":"2022-10-22T12:51:59.000Z","size":105,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-24T09:11:23.009Z","etag":null,"topics":["ios","macos","native-ios","native-macos","objective-c","objectivec","objectivec-interop","unity","unity3d"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gilzoide.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":null,"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},"funding":{"github":["gilzoide"],"patreon":null,"open_collective":null,"ko_fi":"gilzoide","tidelift":null,"community_bridge":null,"liberapay":"gilzoide","issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":null}},"created_at":"2022-10-15T19:18:51.000Z","updated_at":"2024-10-28T09:53:36.000Z","dependencies_parsed_at":"2023-06-09T21:45:38.246Z","dependency_job_id":null,"html_url":"https://github.com/gilzoide/unity-objectivec","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gilzoide%2Funity-objectivec","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gilzoide%2Funity-objectivec/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gilzoide%2Funity-objectivec/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gilzoide%2Funity-objectivec/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gilzoide","download_url":"https://codeload.github.com/gilzoide/unity-objectivec/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248199077,"owners_count":21063641,"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":["ios","macos","native-ios","native-macos","objective-c","objectivec","objectivec-interop","unity","unity3d"],"created_at":"2024-10-10T10:28:20.317Z","updated_at":"2025-04-10T10:21:07.039Z","avatar_url":"https://github.com/gilzoide.png","language":"C#","funding_links":["https://github.com/sponsors/gilzoide","https://ko-fi.com/gilzoide","https://liberapay.com/gilzoide"],"categories":[],"sub_categories":[],"readme":"# Objective-C for Unity\nHigh level C# to Objective-C interface, similar to Unity's [AndroidJavaClass](https://docs.unity3d.com/ScriptReference/AndroidJavaClass.html) and [AndroidJavaObject](https://docs.unity3d.com/ScriptReference/AndroidJavaObject.html).\n\n**WARNING**: this is highly experimental and unsafe, misusage may easily crash the Unity editor or built games!\nUse at your own risk.\n\n**Note**: You have to manage memory on your own, since Automatic Reference Couting (ARC) in Objective-C is a compiler feature and we are not calling the compiler here.\nThis plugin offers some `IDisposable` structures to facilitate this, like `StrongReference` (calls `Release` when disposed) and `DisposablePinnedObject` (pins objects with `GCHandle`, calls `Free` on the handle when disposed).\nYou are responsible for releasing objects you own, as well as knowing which objects are `autorelease`d and should not be `release`d again.\n\n\n## Samples\nThis UPM package has 2 samples:\n- [macOS NSAlert](Samples~/macOS-NSAlert): Sample code that presents a native macOS alert\n- [iOS UIFeedbackGenerator](Samples~/iOS-UIFeedbackGenerator): Sample code that plays haptics using UIImpactFeedbackGenerator on iOS\n\n\n## Usage example\n```cs\n#if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX  // || UNITY_IOS (NSAlert is not support in iOS)\nusing System;\nusing Gilzoide.ObjectiveC;\nusing Gilzoide.ObjectiveC.Foundation;\nusing UnityEngine;\n\npublic static class NSAlertMessage\n{\n  private static Action\u003cId\u003e _onAlertDismissedAction;\n\n  public static void Alert(string message)\n  {\n    // Get existing Objective-C classes using `new Class(\"...\")`\n    Class NSApplication = new Class(\"NSApplication\");\n    // Use `Call` to send messages to an Id or Class using selectors\n    // Selectors must match exactly with the definition, including the `:` characters\n    // When returning values, you MUST pass a type with the right size or the application may crash\n    // `Id` is like Objective-C's `id` type, a dynamic object that can receive messages\n    Id sharedApplication = NSApplication.Call\u003cId\u003e(\"sharedApplication\");\n    // `Get` is just a wrapper over `Call` for the getter selector\n    Id keyWindow = sharedApplication.Get\u003cId\u003e(\"keyWindow\");\n\n    Class NSAlert = new Class(\"NSAlert\");\n    // Instantiate objects with `Alloc(initSelector)` (in Objective-C idiom: `[[Class alloc] init]`)\n    // The return is a StrongReference, a disposable version of `Id` that calls `Release` on Dispose\n    using (StrongReference alert = NSAlert.Alloc(\"init\"))\n    {\n      // Constructors for basic Foundation classes (currently NSString and NSNumber) are available\n      // `+ [NSString stringWith*]` methods return an autoreleased NSString, no need to `Release`\n      AutoreleasedReference\u003cNSString\u003e objcMessage = NSString.StringWith(message);\n\n      // `Set` is just a wrapper over `Call` for the setter selector\n      alert.Set(\"messageText\", objcMessage);\n\n      // Create Objective-C blocks from C# Delegates using `Block.FromDelegate`\n      // Delegates MUST receive the block as first parameter (e.g. with `Id` type), as per block ABI\n      // You are responsible for maintaining the Delegate alive when the block is called\n      // The simplest way is to maintain the Delegate in a static or instance field\n      _onAlertDismissedAction = _block =\u003e Debug.Log($\"Alerted with message: '{message}'\");\n      Block block = Block.FromDelegate(_onAlertDismissedAction);\n      // Blocks are passed by reference in Objective-C, so we need to get its address first\n      // `DisposablePinnedObject` is a disposable wrapper over `GCHandle`\n      using (DisposablePinnedObject pinnedBlock = new DisposablePinnedObject(block))\n      {\n        IntPtr blockByReference = pinnedBlock.Address;\n\n        // You can pass any number of struct values as parameters\n        alert.Call(\"beginSheetModalForWindow:completionHandler:\", keyWindow, blockByReference);\n      }\n    }\n  }\n}\n#endif\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgilzoide%2Funity-objectivec","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgilzoide%2Funity-objectivec","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgilzoide%2Funity-objectivec/lists"}