如何在目标c中定义一个函数

时间:2016-09-03 09:02:16

标签: ios objective-c

我想将此代码从Swift转换为Objective C:

typealias Completion = ([Media]?) -> Void

我已查看Stack Overflow帖子,但我没有看到答案。

2 个答案:

答案 0 :(得分:3)

struct LambdaContainer{ 
    std::function<void(void)> f;
    float x = 10;
}

struct MyClass{
    LambdaContainer c;

}
void someFunction(){
    MyClass ins;
    LambdaContainer cont;
    cont.f = [&cont](){
        // I want to modify 'x' of LambdaContainer that is inside MyClass

        cont.x = 10; // won't work because cont will be copy constructed
                     // and this cont might not exist anymore
    };
    ins.c = cont;
    aVectorSomewhere.push_back(ins);
}

答案 1 :(得分:0)

typedef void (^CompletionBlock) (NSArray* array);