bare::ffi::objc
이 페이지의 내용
API 참조는 영어로만 있습니다. 표준 라이브러리 소스의 영어 문서 주석에서 만듭니다.
Objective-C objects on Apple targets.
Classes and their methods are declared in extern "objc" blocks,
which the compiler turns into a type per class and methods on Id:
each method sends its message with objc_msgSend under the C ABI
of its signature, and its selector is a static reference the runtime
fixes up at load. This module holds what every program shares: Id,
Sel, Class, the root class NSObject, NSString and str,
NSError as Error, autorelease pools and blocks.
An Id<T> owns one retain of its object. Copies share it; the
collector gives it back once no copy is left, and release_now()
gives it back at once. A WeakId<T> refers to an object without
keeping it.
T: IsA<C> says a T is a C: C itself, a superclass, or a
protocol it conforms to. The methods of C are on every Id<T>
with T: IsA<C>, and a parameter of class C takes them.
Modules
blockNabi closures as Objective-C blocks, laid out as the Apple block ABI says.dispatchGrand Central Dispatch: run a closure on the main queue or a global one, through aBlock.errorNSError, what a method that reports through a lastNSError **parameter throws.stringNSStringandstr.subclassclasses made at run time (objc_allocateClassPair): Nabi functions as an Objective-C class's methods, for delegates and the classes an API wants subclassed.
Re-exports
block::{Block, BlockRef}Source
pub use block::{Block, BlockRef}dispatch::{Queue, dispatch_async}Source
pub use dispatch::{Queue, dispatch_async}QueueA dispatch queue (dispatch_queue_t).dispatch_asyncRunblockonqueuelater (dispatch_async); the queue keeps the block until it ran.
error::{Error, NSError}Source
pub use error::{Error, NSError}string::{NSString, ns}Source
pub use string::{NSString, ns}subclass::ClassBuilderSource
pub use subclass::ClassBuilderClassBuilderA class being made: add its methods and protocols, thenregister.
Structs
SelSource
pub struct SelA selector: the name of a method, as the runtime registered it.
The selector named
name("initWithFrame:"), registered with the runtime.Its name, as
registerwas given it.
ClassSource
pub struct ClassA class object.
The class named
name, if the program has loaded it.Its name.
The class as an object pointer, the receiver of a class method.
+[C new]: a new instance, of a classClassBuildermade or another one Nabi has no type for.
NSObjectSource
pub struct NSObjectNSObject, the root class: its methods are on every Id.
IdSource
pub struct Id<T>An Objective-C object of class T (or a subclass of it), holding one
retain. Copies of an Id share that retain; the collector releases
it once no copy is left, and release_now() on any of them gives it
back at once.
Take over the retain the caller owns on
p(a+1result:alloc,new,copy,init);nonefor nil.Safety:
pis nil or an object of classTthe caller owns once.Retain
p, an object the caller does not own (a+0result);nonefor nil.Safety:
pis nil or a live object of classT.The object pointer, for a message send; panics once released.
A retain of the object for a callee that takes one over (an
NS_CONSUMEDparameter).Whether
release_now()gave the object back.Release the object now, not when the last copy goes. Every copy of this
Idthen reads as released, and sending to one panics. A second call does nothing.The same object (and the same retain) as class
U.Safety: the object is a
U;downcastchecks it.The object as a
Uwhen it is one (or a subclass of it).The object as an
NSObject, for a parameter that takes any object.The object as a
U, which aTis (a superclass or a protocol it conforms to):button.upcast::<NSView>().-[NSObject description].-[NSObject hash].-[NSObject isEqual:].-[NSObject isKindOfClass:].-[NSObject respondsToSelector:].-[NSObject class].-[NSObject retainCount], for tests: the count Objective-C code sees, one of which thisIdholds.
WeakIdSource
pub struct WeakId<T>A weak reference to an object: it does not keep the object alive,
and reads as none once the object is deallocated. The answer to a
cycle through Objective-C (a delegate that holds what holds it).
A weak reference to
o's object.The object, retained, while it is alive;
noneafter.Give back the weak slot now, not when the collector does;
loadthen returnsnone.
Traits
ObjectSource
pub trait ObjectA Nabi type standing for an Objective-C class or protocol: the
marker types extern "objc" blocks declare, and NSObject,
NSString, NSError.
The class or protocol name.
The class object; a protocol has none and panics.
Its objects are released on the main thread (
NSView,NSWindowand the otherNSResponders).
IsASource
pub trait IsA<C>A Self is a C: C itself, one of its superclasses, or a
protocol it (or a superclass) conforms to. extern "objc" blocks
declare these.
Functions
newSource
pub fn new<T: Object>() -> Id<T> -[NSObject new] style: an object of class T made with alloc and
init.
autoreleasepoolSource
pub fn autoreleasepool<R>(f: fn() -> R) -> R Run f inside an autorelease pool: objects Objective-C code
autoreleases meanwhile are released when it returns. Wrap loops that
call many methods; each Id keeps its own object regardless.
availableSource
pub fn available(macos: str = "", ios: str = "") -> bool Whether the running OS is the given version or newer: macOS
macos ("13.0"), iOS ios ("16.0"); an empty one (the default)
is any version of that OS. Inside
if objc::available(macos: "13.0", ios: "16.0") { .. } the APIs those
versions brought may be called though the deployment target is older;
the compiler refuses them elsewhere.