Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios reactivecocoa rac绑定布尔数组以设置多重uilabel文本_Ios_Objective C_Reactive Cocoa - Fatal编程技术网

Ios reactivecocoa rac绑定布尔数组以设置多重uilabel文本

Ios reactivecocoa rac绑定布尔数组以设置多重uilabel文本,ios,objective-c,reactive-cocoa,Ios,Objective C,Reactive Cocoa,我有一个statusArray,用于显示UILabel文本 基于布尔值 喂,我给你看些东西 然后0显示其他字符串 我应该如何使用rac作为反应可可粉?目前我只想到两种方法: 收听bool变量 您需要使用bool变量作为属性 @weakify(self); [RACObserve(self, bool) subscribeNext:^(id _Nullable x) { @strongify(self); self.label.text = [x boolValue] ? @

我有一个statusArray,用于显示UILabel文本

基于布尔值

喂,我给你看些东西 然后0显示其他字符串


我应该如何使用rac作为反应可可粉?

目前我只想到两种方法:

  • 收听
    bool
    变量
  • 您需要使用
    bool
    变量作为属性

    @weakify(self);
    [RACObserve(self, bool) subscribeNext:^(id  _Nullable x) {
         @strongify(self);
         self.label.text = [x boolValue] ? @"a" : @"b";
    }];
    
    这将导致循环引用,因此使用
    weakify
    strongify
    ,这也是
    ReactiveCocoa
    的一部分,以及
    RACEXTScope.h

    /**
     * Creates \c __weak shadow variables for each of the variables provided as
     * arguments, which can later be made strong again with #strongify.
     *
     * This is typically used to weakly reference variables in a block, but then
     * ensure that the variables stay alive during the actual execution of the block
     * (if they were live upon entry).
     *
     * See #strongify for an example of usage.
     */
    #define weakify(...) \
        rac_keywordify \
        metamacro_foreach_cxt(rac_weakify_,, __weak, __VA_ARGS__)
    
    /**
     * Strongly references each of the variables provided as arguments, which must
     * have previously been passed to #weakify.
     *
     * The strong references created will shadow the original variable names, such
     * that the original names can be used without issue (and a significantly
     * reduced risk of retain cycles) in the current scope.
     *
     * @code
    
        id foo = [[NSObject alloc] init];
        id bar = [[NSObject alloc] init];
    
        @weakify(foo, bar);
    
        // this block will not keep 'foo' or 'bar' alive
        BOOL (^matchesFooOrBar)(id) = ^ BOOL (id obj){
            // but now, upon entry, 'foo' and 'bar' will stay alive until the block has
            // finished executing
            @strongify(foo, bar);
    
            return [foo isEqual:obj] || [bar isEqual:obj];
        };
    
     * @endcode
     */
    #define strongify(...) \
        rac_keywordify \
        _Pragma("clang diagnostic push") \
        _Pragma("clang diagnostic ignored \"-Wshadow\"") \
        metamacro_foreach(rac_strongify_,, __VA_ARGS__) \
        _Pragma("clang diagnostic pop")
    
  • 绑定
    UILabel.text
    ,将
    bool
    信号转换为
    string
    赋值

  • 第一种方法是保持循环。你应该总是更喜欢第二个。然后你应该写你从哪里得到这样的宏:)@Cy-4AH,因为
    weakify
    strongify
    reactivecococoa
    的一部分,所以我没有写,我会改进它。它是一系列布尔和标签。。这不起作用。状态和标签是一一对应的。首先像这样绑定数据,然后遍历它。我现在猜您想在
    UITableView
    上使用它,那么每个
    UITableViewCell
    都会得到一个
    Bool
    值。
    RAC(self.label, text) = [RACObserve(self, bool) map:^id _Nullable(id  _Nullable value) {
         return [value boolValue] ? @"a" : @"b";
    }];