how to return array in objc?


static extern(iOS) int[] GetIntArrayTest() {

NSArray *temp = [NSArray arrayWithObjects: @1, @2, nil];

return temp;


I want to return int array from iOS.

but I don’t know ObjectiveC.

My error message is

error: cannot initialize return object of type 'id<UnoArray>' with an lvalue of type 'NSArray *'

Please help me.

ps. I did read ‘’ but I don’t understand and here was no return array.


Good question. Something like the following should do it:

int length = 2;
@{int[]} temp = @{int[]:New(length)};
temp[0] = @1;
temp[1] = @2;
return temp;

The reason your code didn’t work is that Uno arrays are not automatically converted to NSArray* in foreign Objective-C since this is not always what you want. You can instead use macros as above to create Uno arrays, fill them, and return them from foreign code. I’ll make an internal issue on improving the documentation on this.

Hate to hijack this thread, but the troubles I’m having seemed relevant.

I’ve got something like the following. someNativeLibrary has a method that takes a block (provided with an NSArray* argument). On the Uno side, I have an Action that needs to be called with those arguments:

public void Example(Action<string, object[]> messageHandler)
  return [someNativeLibrary withCallback:^(NSString* action, NSArray* args) {

          // create Uno array
          int count = 0;
          @{object[]} unoArgs = nil;
          if (args != nil) {
            count = args.count;
            unoArgs = @{object[]:New(count)};

            // iterate and copy over
            int i = 0;
            for (i = 0; i < count; i++) {
              // first, I tried this, but it failed:
              // unoArgs[i] = args[i];

              // then, I tried this, but it failed trying to call selector `unoObject` on the 
              // NSString* that was the first element of the array
              id<UnoObject> a = args[i];
              @{object[]:Of(unoArgs).Set(i, a)};

          // here is where I pass those arguments to the passed in Action
          messageHandler(action, unoArgs);

How do I convert that NSArray* provided to the block to an object[] that my Uno Action can handle?

Please create a new thread

Sure thing. I’ll create a new thread this evening. Thanks!