简体   繁体   English

将数组从 objc 传递到 Swift

[英]passing an array from objc to Swift

I have this code in objc that creates an array with some values from realm我在 objc 中有这段代码,它使用 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.我想在我的 swift class 中访问该数组以填充一些下拉菜单。 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?如何调用 objc 数组?

The menuTest function returns void, if you want to access the array you have to change it in this way: menuTest function 返回 void,如果要访问数组,则必须以这种方式更改它:

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM