Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 文件搜索花费太多时间_Objective C_Cocoa Touch - Fatal编程技术网

Objective c 文件搜索花费太多时间

Objective c 文件搜索花费太多时间,objective-c,cocoa-touch,Objective C,Cocoa Touch,我试图在这里搜索名为1到6的plist,我写了这段代码,它使应用程序的加载时间比原始时间多了3秒……代码是 for (int i=1;i<6;i++) { NSString *bundleRoot = [[NSBundle mainBundle] bundlePath]; NSArray *dirContents = [[NSFileManager defaultManager] directoryContentsAtPath:bundleRoot]; for (N

我试图在这里搜索名为1到6的plist,我写了这段代码,它使应用程序的加载时间比原始时间多了3秒……代码是

for (int i=1;i<6;i++) {
    NSString *bundleRoot = [[NSBundle mainBundle] bundlePath];
    NSArray *dirContents = [[NSFileManager defaultManager] directoryContentsAtPath:bundleRoot];
    for (NSString *tString in dirContents) {
        if ([tString hasPrefix:[NSString stringWithFormat:@"%d",i]] && [tString hasSuffix:@".plist"]) { 
            NSLog(@"file found");
            NSString *plist = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%d",i] ofType:@"plist"];
            mute = [NSMutableArray arrayWithContentsOfFile:plist];
            [mute addObjectsFromArray:contentArray];
            contentArray = mute;
        }
        else {
            NSLog(@"not found");
        }
    }
}

for(inti=1;i这不是很有效:)

试试这个:

for (int i = 1; i <= 6; ++i) {
  // Load the plist
  NSString *plist = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%d",i] ofType:@"plist"];
  if (nil == plist) {
    NSLog(@"not found (%i)", i);
    continue;
  }

  // Do something with your plist
  mute = [NSMutableArray arrayWithContentsOfFile:plist];
  [contentArray addObjectsFromArray:mute];
}

for(inti=1;i这不是很有效:)

试试这个:

for (int i = 1; i <= 6; ++i) {
  // Load the plist
  NSString *plist = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%d",i] ofType:@"plist"];
  if (nil == plist) {
    NSLog(@"not found (%i)", i);
    continue;
  }

  // Do something with your plist
  mute = [NSMutableArray arrayWithContentsOfFile:plist];
  [contentArray addObjectsFromArray:mute];
}

for(inti=1;i循环不会运行6次,它只会运行5次:)+1@LegendReborn:)(尽管你可能只是让他的代码慢了20%!我只想让它运行5次。。。错误地写了6次…循环不会运行6次,它只会运行5次:)+1@LegendReborn:)(尽管你可能只是让他的代码慢了20%!我只想让它运行5次。。。错误地写了6个…但是它仍然需要太多的时间来加载,plist有50个条目,这可能是问题所在。。每个条目都是一个100字的笑话,如果你制作了contentArray NSMutableArray,你可以让每个plist在那里稍微快一点(参见我的编辑)。尽管我怀疑这会有很大的不同。要花多长时间?哇,真是太长时间了!你想过改用数据库吗?多亏了你,现在的加载时间是4秒,这是我以前使用旧代码时的7秒,现在是4秒,就像你在原始问题中提到的3秒一样,已经过去了。我怀疑延迟是由应用程序中的其他地方引起的,因为这不可能需要4秒!你有没有试过使用仪器,看看是什么占用了你的时间?4秒的启动时间也没那么糟糕-你可以在以后的版本中发布并改进它。但是它仍然需要花费太多的时间来加载,plist有50个条目,这可能是问题所在。。每个条目都是一个100字的笑话,如果你制作了contentArray NSMutableArray,你可以让每个plist在那里稍微快一点(参见我的编辑)。尽管我怀疑这会有很大的不同。要花多长时间?哇,真是太长时间了!你想过改用数据库吗?多亏了你,现在的加载时间是4秒,这是我以前使用旧代码时的7秒,现在是4秒,就像你在原始问题中提到的3秒一样,已经过去了。我怀疑延迟是由应用程序中的其他地方引起的,因为这不可能需要4秒!你有没有试过使用仪器,看看是什么占用了你的时间?4秒的开始时间也没那么糟糕——你可以在以后的版本中发布并改进它。