Skip to content

Instantly share code, notes, and snippets.

@remstos
Created July 18, 2015 11:25
Show Gist options
  • Save remstos/0a32e8c272c3ccf567db to your computer and use it in GitHub Desktop.
Save remstos/0a32e8c272c3ccf567db to your computer and use it in GitHub Desktop.
React UI Manager bridge to use with Swift
//
// RCTUIManager+Swift.h
// RCTUIManager+Swift
//
// Created by Remi Santos on 30/06/15.
// Copyright © 2015 Facebook. All rights reserved.
//
#import "RCTUIManager.h"
#import "RCTSParseArray.h"
@interface RCTUIManager (Swift)
-(void)swift_addUIBlock:(void (^)(RCTUIManager*, RCTSparseArray*))block;
@end
//
// RCTUIManager+Swift.m
// RCTUIManager+Swift
//
// Created by Remi Santos on 30/06/15.
// Copyright © 2015 Facebook. All rights reserved.
//
#import "RCTUIManager+Swift.h"
@implementation RCTUIManager (Swift)
-(void)swift_addUIBlock:(void (^)(RCTUIManager*, RCTSparseArray*))block {
[self addUIBlock:^(RCTUIManager *uiManager, RCTSparseArray*viewRegistry) {
block(uiManager, viewRegistry);
}];
}
@end
@remstos
Copy link
Author

remstos commented Jul 18, 2015

It allows you to write this in Swift

uiManager.swift_addUIBlock { (uiManager, viewRegistry) -> Void in
      // Do whatever you want
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment