TLSignals 0.1.2

TLSignals 0.1.2

测试已测试
语言语言 Obj-CObjective C
许可 自定义
发布最后发布2014年12月

未知 维护。



TLSignals 0.1.2

  • 作者
  • Sergey Egorov

Objective-C++ 信号

示例

让我向您展示如何使用 TLSignal 轻松地观察某个对象的通知。例如,我们有 ExampleViewController,我们想了解其视图何时加载。

ExampleViewController.mm

#import "Signals.h"

@interface ExampleViewController : UIViewController

@property (nonatomic, readonly) TLSignal<UIView *> *viewDidLoadSignal;

@end

@implementation ExampleViewController

tl_synthesize_signal(viewDidLoadSignal, UIView *);

-(void)viewDidLoad
{
    [super viewDidLoad];
    // Notifying watchers about viewDidLoad event
    self.viewDidLoadSignal->notify(self.view);
}

@end

很简单,对吧?

AppDelegate.mm

#import "AppDelegate.h"
#import "ExampleViewController.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)options
{
    UIWindow window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.viewController = [[ExampleViewController alloc] initWithNibName:@"ExampleViewController" bundle:nil];

    // Subscribe to our event
    self.viewController.viewDidLoadSignal->addObserver(^(TLSignal<UIView *> *signal, UIView *targetView)
    {
        targetView.backgroundColor = [UIColor blackColor];
    });

    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
    return YES;
}

@end

许可

MIT 许可证下授权