passing an array from objc to Swift

Viewed 353

I have this code in objc that creates an array with some values from realm

get.m

-(void) menuTest {
RLMResults<activity *> *test = [activity allObjects];
NSMutableArray *tmpArray = [[NSMutableArray alloc] init];

 for(activity *n in test){
    [tmpArray addObject:n];
   }
}

And I want to have access to that array in my swift class to populate some dropdown menu. As of now I am calling it like this but it tells me it doesn't conform to protocol.

let get = get()
    for n in get.menuTest(){
        array.append(n)
    }

How can I make a call to the objc array?

1 Answers

The menuTest function returns void, if you want to access the array you have to change it in this way:

- (NSMutableArray*)menuItems {
    RLMResults<activity *> *test = [activity allObjects];
    NSMutableArray *tmpArray = [[NSMutableArray alloc] init];

    for(activity *n in test){
       [tmpArray addObject:n];
    }
    return tmpArray
} 
Related