Skip to content

Latest commit

 

History

History
74 lines (55 loc) · 1.48 KB

readme.md

File metadata and controls

74 lines (55 loc) · 1.48 KB

rococoa-core

How To

Class

/** the object root is NSObject */
public abstract class FooClass extends NSObject {

    static {
        FooLibrary.instance.toString(); // to make sure library is loaded (optional)
    }

    private static final _Class CLASS;

    /**
     * '-' methods: - init*:
     */
    public abstract void initWithBar(Bar bar);

    /** '+' methods */
    public interface _Class extends ObjCClass {
        /** + alloc: */
        FooClass alloc();

        /** + withString: */
        FooClass withString(String string);
    }

    /**
     * property getter: someProperty
     */
    public abstract int someProperty();

    /**
     * property setter: someProperty
     */
    public abstract void setSomeProperty(int some);

    /**
     * '-' methods: - doSomething:bar:
     */
    public abstract void doSomething_bar(Bar bar);
 }

Error Handling

    ObjCObjectByReference errorRef = new ObjCObjectByReference();
    ... foo.bar_error(..., errorRef);
    NSError error = errorRef.getValueAs(NSError.class);
    if (error != null) {
        throw new BuzException(error.description());
    }

Run on main thread

   Foundation.runOnMainThread(() -> { ... });

Cast

    if (objcObject.isKindOfClass(fooObjcClass))
        FooObjcObject fooObjcObject = Rococoa.cast(objcObject, FooObjcClass.class);

References