美文网首页
RAC的初次使用

RAC的初次使用

作者: ldhonline | 来源:发表于2018-10-13 15:22 被阅读0次

    一、Pod 安装 RAC

    1. 在项目根目录初始化 pod
    pod init
    

    命令会自动创建一个 Podfile 文件。

    1. 在Podfile文件中添加依赖
    # Uncomment the next line to define a global platform for your project
    platform :ios, '9.0'
    
    target 'uiview' do
      # Uncomment the next line if you're using Swift or would like to use dynamic frameworks
      # use_frameworks!
    
      # Pods for uiview
    
    pod 'ReactiveObjC', '~> 3.1.0'
    pod 'Masonry', '~> 1.0.2'
    
    end
    
    1. 安装依赖
    pod install
    

    项目会自动转换为 pod 管理模式,并安装好所有清单中的依赖。

    1. 添加 RAC 的头文件引用
    #import "ReactiveObjecC.h"
    

    二、使用 RAC 连接组件

    1. 使用 @weakinfo(self) 弱化引用, 在闭包中使用 @strongify(self) 强化引用。
    - (void)bindComponents{
        @weakify(self);
        [[self.textView rac_textSignal] subscribeNext:^(NSString * _Nullable x) {
            @strongify(self);
            self.myView.text = x;
        }];
    }
    

    相关文章

      网友评论

          本文标题:RAC的初次使用

          本文链接:https://www.haomeiwen.com/subject/edmoaftx.html