Module objc::declare [] [src]

Functionality for declaring Objective-C classes.

Classes can be declared using the ClassDecl struct. Instance variables and methods can then be added before the class is ultimately registered.

Example

The following example demonstrates declaring a class named MyNumber that has one ivar, a u32 named _number and a number method that returns it:

let superclass = Class::get("NSObject").unwrap();
let mut decl = ClassDecl::new(superclass, "MyNumber").unwrap();

// Add an instance variable
decl.add_ivar::<u32>("_number");

// Add an ObjC method for getting the number
extern fn my_number_get(this: &Object, _cmd: Sel) -> u32 {
    unsafe { *this.get_ivar("_number") }
}
unsafe {
    decl.add_method(sel!(number),
        my_number_get as extern fn(&Object, Sel) -> u32);
}

decl.register();

Structs

ClassDecl

A type for declaring a new class and adding new methods and ivars to it before registering it.

UnequalArgsError

An error returned from MethodImplementation::imp_for to indicate that a selector and function accept unequal numbers of arguments.

Traits

MethodImplementation

Types that can be used as the implementation of an Objective-C method.