0

配列に文字列オブジェクトを入力しています。これらは何千もある可能性があります。私はforループ内で多くの割り当てと初期化を行っていますが、これは高価であることがわかっています。これを行うためのより良い、より効率的な方法は何ですか?

ありがとう

 //loop through the array of dictionaries
 for(NSUInteger i =0; i < [latestResults count]; i++){

        self.workingEntry = [[AppRecord alloc] init];

        //Get the next dictionary from the array of dictionaries
        NSDictionary *currentRecord = [latestResults objectAtIndex:i];


        //Set the object
        [self.workingEntry setAppURLString:[currentRecord valueForKeyPath:@"id.label"]];
        [self.workingEntry setAppName:[currentRecord valueForKeyPath:@"im:name.label"]];

        NSArray *imageArray = [currentRecord valueForKeyPath:@"im:image.label"];

        [self.workingEntry setImageURLString:[imageArray objectAtIndex:0]];
        [self.workingEntry setArtist:[currentRecord valueForKeyPath:@"im:artist.label"]];

       //Add object to array
       [self.workingArray addObject:self.workingEntry];

        currentRecord = nil;
        self.workingEntry = nil;
        imageArray = nil;


    }
4

1 に答える 1

2

袖口から離れると、私はへのvalueForKeyPath:呼び出しよりもそれらすべての呼び出しについてもっと心配するでしょう+alloc

ただし、測定されるまでは関係ありません。

割り当ての数を減らしたい場合は、シングルトン、グローバルキャッシュ、またはその他のメカニズムを使用してオブジェクトを一意化するように移動します。もちろん、キャッシュのメンテナンスでパフォーマンスのボトルネックになるリスクがあります。

于 2012-09-14T16:12:10.617 に答える