### Install ObjectiveC.jl Source: https://github.com/juliainterop/objectivec.jl/blob/master/README.md Installs the ObjectiveC.jl package using Julia's package manager. ```julia Pkg.add("ObjectiveC") ``` -------------------------------- ### Define Objective-C Properties with @objcproperties Source: https://github.com/juliainterop/objectivec.jl/blob/master/README.md Demonstrates using the `@objcproperties` macro to automatically generate Julia property accessors (`getproperty`, `setproperty!`, `propertynames`) for Objective-C properties. This example automatically generates a getter for `pointerValue`. ```julia using ObjectiveC @objcproperties NSValue begin @autoproperty pointerValue::Ptr{Cvoid} end # Example usage: # obj.pointerValue ``` -------------------------------- ### Foundation API Wrappers Source: https://github.com/juliainterop/objectivec.jl/blob/master/README.md Demonstrates the usage of ObjectiveC.jl's wrappers for the Foundation framework, including NSString, NSArray, and NSDictionary. ```julia using .Foundation str = NSString("test") println(str) array = NSArray([str, str]) println(array) dict = NSDictionary(Dict(str=>str)) println(dict) println(d[str]) println(Dict{NSString,NSString}(d)) ``` -------------------------------- ### Basic Objective-C Method Call Source: https://github.com/juliainterop/objectivec.jl/blob/master/README.md Demonstrates calling an Objective-C method (`new`) on a class (`NSString`) using the `@objc` macro. Requires specifying the return type using Julia's type-assertion syntax. ```julia using ObjectiveC @objc [NSString new]::id{Object} ``` -------------------------------- ### Customizing @objcproperties Source: https://github.com/juliainterop/objectivec.jl/blob/master/README.md Illustrates advanced customization options for the `@objcproperties` macro, including generating setters, handling Objective-C object pointers with type conversion, and manually defining property accessors. ```julia using ObjectiveC # @objcproperties SomeObject begin # @autoproperty someProperty::DstTyp # @autoproperty someProperty::DstTyp setter=setSomeProperty # @autoproperty someProperty::id{DstTyp} # @autoproperty someStringProperty::id{NSString} type=String # @getproperty someComplexProperty function(obj) # # custom getter logic # end # @setproperty! someComplexProperty function(obj, val) # # custom setter logic # end # end ``` -------------------------------- ### Convert Julia Callable to Objective-C Block Source: https://github.com/juliainterop/objectivec.jl/blob/master/README.md Shows how to convert a Julia function (`hello`) into an Objective-C block using the `@objcblock` macro. This allows passing Julia code to Objective-C methods that expect blocks. Note: thread safety considerations apply for Julia versions before 1.9. ```julia using ObjectiveC function hello(x) println("Hello, $x!") x+1 end block = @objcblock(hello, Cint, (Cint,)) ``` -------------------------------- ### Enable Tracing for Objective-C Calls Source: https://github.com/juliainterop/objectivec.jl/blob/master/README.md Shows how to enable and disable tracing in ObjectiveC.jl to view underlying Objective-C calls for debugging purposes. Requires a Julia session restart for changes to take effect. ```julia using ObjectiveC ObjectiveC.enable_tracing(true) # Restart Julia session using ObjectiveC str = NSString("test"); println(String(str)) ``` -------------------------------- ### Create Objective-C Wrapper Source: https://github.com/juliainterop/objectivec.jl/blob/master/README.md Uses the `@objcwrapper` macro to create a Julia wrapper for an Objective-C class (`NSValue`). This generates an abstract type for the class hierarchy and a concrete structure for object pointers, simplifying interaction. ```julia using ObjectiveC @objcwrapper NSValue obj_ptr = @objc [NSValue valueWithPointer:C_NULL::Ptr{Cvoid}]::id{NSValue} obj = NSValue(obj_ptr) ``` -------------------------------- ### Asynchronous Objective-C Block with Callback Source: https://github.com/juliainterop/objectivec.jl/blob/master/README.md Demonstrates using the `@objcasyncblock` macro to create an Objective-C block that executes asynchronously and triggers a callback (`AsyncCondition`). This is useful for handling blocks that might be called from unrelated threads, especially in older Julia versions. ```julia using ObjectiveC using Base counter = 0 cond = AsyncCondition() do async_cond counter += 1 end block = @objcasyncblock(cond) ``` -------------------------------- ### Access Objective-C Property Value Source: https://github.com/juliainterop/objectivec.jl/blob/master/README.md Defines a Julia function `get_pointer` to retrieve the `pointerValue` property from an `NSValue` object using the `@objc` macro. This showcases accessing Objective-C properties through Julia. ```julia using ObjectiveC get_pointer(val::NSValue) = @objc [val::id{NSValue} pointerValue]::Ptr{Cvoid} ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.