gpt4 book ai didi

ios - 在 ViewController 中调用 App delegate 数组

转载 作者:行者123 更新时间:2023-11-28 21:29:10 25 4
gpt4 key购买 nike

我在 AppDelegate 中启动应用程序时加载了一些数组。谁能告诉我如何调用 ViewController 中的数组以供使用? AppDelegate中的代码如下:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

// Override point for customization after application launch.

Myclass *myclass = [[Myclass alloc] init];

NSArray *W1 = [NSArray arrayWithObjects:[NSArray arrayWithObjects:[NSArray arrayWithObjects:[NSArray array], nil], nil], nil];
// NSArray *stringW1 = [myclass arrayFromContentsOfFileWithName:@"W1_custom2Float"];
W1 = [myclass textToArray4dimFloat:@"W1_custom3_MOCVN_v3_wsqrt" dimension1:32 dimension2:1 dimension3:5 dimension4:5];
// W1 = [myclass textToArray4dimFloat:@"W1" dimension1:32 dimension2:1 dimension3:5 dimension4:5];

// NSLog(@"W1 is read");

NSArray *W2 = [NSArray arrayWithObjects:[NSArray arrayWithObjects:[NSArray arrayWithObjects:[NSArray array], nil], nil], nil];
// NSArray *stringW2 = [myclass arrayFromContentsOfFileWithName:@"W2_custom2Float"];
W2 = [myclass textToArray4dimFloat:@"W2_custom3_MOCVN_v3_wsqrt" dimension1:64 dimension2:32 dimension3:5 dimension4:5];
// W2 = [myclass textToArray4dimFloat:@"W2" dimension1:64 dimension2:32 dimension3:5 dimension4:5];

// NSLog(@"W2 is read");

NSArray *Wf1 = [NSArray arrayWithObjects:[NSArray array], nil];
// NSArray *stringWf1 = [myclass arrayFromContentsOfFileWithName:@"Wf1_custom2Float"];
Wf1 = [myclass textToArray2dimFloat:@"Wf1_custom3_MOCVN_v3_wsqrt" dimension1:3136 dimension2:1024];
// Wf1 = [myclass textToArray2dimFloat:@"Wf1" dimension1:3136 dimension2:1024];

// NSLog(@"Wf1 is read");

NSArray *Wf2 = [NSArray arrayWithObjects:[NSArray array], nil];
// NSArray *stringWf2 = [myclass arrayFromContentsOfFileWithName:@"Wf2_custom2Float"];
Wf2 = [myclass textToArray2dimFloat:@"Wf2_custom3_MOCVN_v3_wsqrt" dimension1:1024 dimension2:17];
// Wf2 = [myclass textToArray2dimFloat:@"Wf2" dimension1:1024 dimension2:14];

// NSLog(@"Wf2 is read");
//
NSArray *B1 = [NSArray array];
// NSArray *stringB1 = [myclass arrayFromContentsOfFileWithName:@"B1_custom2Float"];
B1 = [myclass textToArray1dimFloat:@"B1_custom3_MOCVN_v3_wsqrt" dimensions:32];
// B1 = [myclass textToArray1dimFloat:@"B1" dimensions:32];

// NSLog(@"B1 is read");

NSArray *B2 = [NSArray array];
// NSArray *stringB2 = [myclass arrayFromContentsOfFileWithName:@"B2_custom2Float"];
B2 = [myclass textToArray1dimFloat:@"B2_custom3_MOCVN_v3_wsqrt" dimensions:64];
// B2 = [myclass textToArray1dimFloat:@"B2" dimensions:64];

// NSLog(@"B2 is read");

NSArray *Bf1 = [NSArray array];
// NSArray *stringBf1 = [myclass arrayFromContentsOfFileWithName:@"Bf1_custom2Float"];
Bf1 = [myclass textToArray1dimFloat:@"Bf1_custom3_MOCVN_v3_wsqrt" dimensions:1024];
// Bf1 = [myclass textToArray1dimFloat:@"Bf1" dimensions:1024];

// NSLog(@"Bf1 is read");

NSArray *Bf2 = [NSArray array];
// NSArray *stringBf2 = [myclass arrayFromContentsOfFileWithName:@"Bf2_custom2Float"];
Bf2 = [myclass textToArray1dimFloat:@"Bf2_custom3_MOCVN_v3_wsqrt" dimensions:17];
// Bf2 = [myclass textToArray1dimFloat:@"Bf2" dimensions:14];

return YES;
}

W1、W2、Wf1、Wf2、B1、B2、Bf1、Bf2 是数组。

最佳答案

您需要将这些对象添加到.h文件

@property (strong, nonatomic)NSArray *W1;

然后将值分配给 didFinishLaunchingWithOptions。示例如下

self.W1 = [myclass textToArray4dimFloat:@"W1_custom3_MOCVN_v3_wsqrt" dimension1:32 dimension2:1 dimension3:5 dimension4:5];

现在您可以在任何地方将所有这些属性访问到应用程序中。

    #include "MyAppDelegate.h"
NSArray *arObj = ((MyAppDelegate *)[UIApplication sharedApplication].delegate). W1;

关于ios - 在 ViewController 中调用 App delegate 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36860035/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com