NSObject 到 React-Native 对象

War*_*blr 5 javascript ios react-native

如果我定义了一个 NSObject:

// Person.h
@interface Person : NSObject
@property(nonatomic,copy)NSString *uuid;
@property(nonatomic,copy)NSString *firstName;
@property(nonatomic,copy)NSString *lastName;
@end
Run Code Online (Sandbox Code Playgroud)

...我想为我的Persons提供一个数组,我ReactPeopleView该如何将Person对象传递给我的 React 视图?

当我尝试:

NSArray *people = [PeopleManager getAllPeople]; // returns an array of People objects
NSDictionary *properties = @{"people":people};
RCTRootView *root = [[RCTRootView alloc] initWithBridge:_bridge
                                     moduleName:@"ReactPeopleView"
                              initialProperties:properties];
Run Code Online (Sandbox Code Playgroud)

……结果是:

Running application "ReactPeopleView" with appParams: {"rootTag":1,"initialProps":{"people":[]}. __DEV__ === true, development-level warning are ON, performance optimizations are OFF
Run Code Online (Sandbox Code Playgroud)

在哪里'people':[],但它没有得到任何对象。我 100% 它们在传递到反应之前存在于数组中(我可以在 NSArray 的 NSLog 中看到它们,people.

我对 react-native 很陌生,已经玩了几个星期了。使用 ObjC 编码大约 10 年。任何帮助深表感谢。

更新 2016-08-30: 我一直跟踪 react 视图的实例化-(void)_executeJSCall:arguments:callback:......我传入的参数在整个过程中都是正确的,所以我不确定哪里丢失了。

2016 年 8 月 31 日更新: 我最终只向-(NSDictionary *)toDictionary;我的每个 NSObject 类添加了一个函数。在将它们发送到 ReactPeopleView 之前以这种方式转换它们似乎有效;虽然不理想。任何有更好解决方案的人请分享:)