如何在WatchKit中使用"context"传递多个对象

Fai*_*yed 1 objective-c ios watchkit

我正在使用以下代码将数据传递给我的第三个控制器:

[self presentControllerWithName:@"ThirdView" context:MyArray];
Run Code Online (Sandbox Code Playgroud)

问题是,我想传递的不仅仅是一个简单的数组.我想传递一个单独的字符串,如果可能的话,另一个数组,我不想将字符串或其他数组添加到"MyArray".

有没有不同的方法来解决这个问题,或者我只是重构这个代码?

Gre*_*reg 5

您可以使用要传递的数据创建自定义对象,也可以将数据捆绑在字典或数组中.在swift中你也可以使用元组.

这是字典的一个例子:

NSDictionary *myData = @{
    @"MainArray" : MyArray,
    @"MyString" : @"string",
    @"AnotherArray" : anotherArray
};
[self presentControllerWithName:@"ThirdView" context: myData];
Run Code Online (Sandbox Code Playgroud)

数组示例:

NSArray *myData = @[MyArray, @"string", anotherArray];
[self presentControllerWithName:@"ThirdView" context: myData];
Run Code Online (Sandbox Code Playgroud)