2011-01-11 175 views
0

我有一些代碼,但我看不到如何優化它。 Allthough我知道代碼寫得很糟(我自己)。viewDidLoad - 代碼優化

我所擁有的是火車站名稱列表。我想要做的就是將這些電臺名稱添加到桌面視圖中,併爲每個電臺名稱的第一個字母設置一個部分。應該跳過那些沒有任何電臺的部分。

第一部分應該被稱爲「 - 」,並應顯示最近的車站。

例子:

--A-- 
Astation C 
Alaska C 
Alabama C 
--C-- 
Cstation 
Cathedral station 
Central station 

所以我得到了這一切工作,但我覺得我做的不怎麼樣,應該有一個更簡單的方法。此外,在我的iPhone 4上加載此視圖時,該應用程序會掛起1秒鐘。這也不算什麼。 這是我的代碼:

- (void)viewDidLoad{ 
    self.filteredListContent = [NSMutableArray array]; 

    UIBarButtonItem *rightBarButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSearch 
                        target:self 
                        action:@selector(searchBar:)]; 
    self.navigationItem.rightBarButtonItem = rightBarButton; 

    [rightBarButton release]; 

    UISearchBar *mySearchBar = [[UISearchBar alloc] init]; 
    mySearchBar.delegate = self; 
    [mySearchBar setAutocapitalizationType:UITextAutocapitalizationTypeNone]; 
    [mySearchBar sizeToFit]; 
    theTable.tableHeaderView = mySearchBar; 

    if (UIInterfaceOrientationLandscapeRight == [[UIDevice currentDevice] orientation] || 
     UIInterfaceOrientationLandscapeLeft == [[UIDevice currentDevice] orientation]) 
    { 
     theTable.tableHeaderView.frame = CGRectMake(0.f, 0.f, 480.f, 44.f); 
    } 
    else 
    { 
     theTable.tableHeaderView.frame = CGRectMake(0.f, 0.f, 320.f, 44.f); 
    } 

    searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:mySearchBar contentsController:self]; 
    [self setSearchDisplayController:searchDisplayController]; 
    [searchDisplayController setDelegate:self]; 
    [searchDisplayController setSearchResultsDataSource:self]; 

    [mySearchBar release]; 

    /* Set the data */ 
    NSArray *stationenPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *stationenDocumentsDirectory = [stationenPath objectAtIndex:0]; 
    NSString *path = [stationenDocumentsDirectory stringByAppendingPathComponent:@"stations.plist"]; 

    NSDictionary* stationenDictionary = [[[NSDictionary alloc] initWithContentsOfFile:path] autorelease]; 
    xmlStationenList* stationsXml = [[xmlStationenList alloc] initWithDictionary:stationenDictionary]; 

    NSSortDescriptor *stationSorter = [[NSSortDescriptor alloc] initWithKey:@"_station" ascending:YES]; 
    NSMutableArray *xmlResult = [stationsXml getTimeResult]; 

    NSArray *objects = [[[NSArray alloc] initWithObjects:stationSorter,nil] autorelease]; 
    [xmlResult sortUsingDescriptors:objects]; 

    [stationSorter release]; 

    /* prefName is decided by the page opening chooseStationViewController. Using this class init function */ 
    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; 
    self.prefValue = [prefs valueForKey:prefName]; 

    self.listContent = [NSMutableArray array]; 

    for (stationenListSet *theList in xmlResult) 
    { 
     [self.listContent addObject:[theList get_station]]; 
    } 
    /* END set the data */ 

    /* Set sections */ 
    self.sectionArray = [NSMutableArray array]; 
    [self.sectionArray addObject:@"-"]; 
    [self.sectionArray addObject:@"A"]; 
    [self.sectionArray addObject:@"B"]; 
    [self.sectionArray addObject:@"C"]; 
    [self.sectionArray addObject:@"D"]; 
    [self.sectionArray addObject:@"E"]; 
    [self.sectionArray addObject:@"F"]; 
    [self.sectionArray addObject:@"G"]; 
    [self.sectionArray addObject:@"H"]; 
    [self.sectionArray addObject:@"I"]; 
    [self.sectionArray addObject:@"J"]; 
    [self.sectionArray addObject:@"K"]; 
    [self.sectionArray addObject:@"L"]; 
    [self.sectionArray addObject:@"M"]; 
    [self.sectionArray addObject:@"N"]; 
    [self.sectionArray addObject:@"O"]; 
    [self.sectionArray addObject:@"P"]; 
    [self.sectionArray addObject:@"Q"]; 
    [self.sectionArray addObject:@"R"]; 
    [self.sectionArray addObject:@"S"]; 
    [self.sectionArray addObject:@"T"]; 
    [self.sectionArray addObject:@"U"]; 
    [self.sectionArray addObject:@"V"]; 
    [self.sectionArray addObject:@"W"]; 
    [self.sectionArray addObject:@"X"]; 
    [self.sectionArray addObject:@"Y"]; 
    [self.sectionArray addObject:@"Z"]; 
    [self.sectionArray addObject:@"Å"]; 
    [self.sectionArray addObject:@"Ä"]; 
    [self.sectionArray addObject:@"Ö"]; 

    [sectionSubArray release]; 
    sectionSubArray = [[NSMutableArray alloc] init]; 
    NSMutableArray *sectionTempArray = [[NSMutableArray alloc] init]; 

    [sectionTempArray addObject:@"-"]; 
    [sectionSubArray addObject:[[NSArray alloc] init]]; 

    for(NSString *sectionChar in self.sectionArray) 
    { 
     sectionChar = [sectionChar uppercaseString]; 
     int i = 0; 

     NSMutableArray *sectionRowArray = [[NSMutableArray alloc] init]; 
     for (NSString* theStation in listContent) 
     { 
      NSString *firstChar = [[NSString alloc] initWithFormat:@"%C", toupper([theStation characterAtIndex:0])]; 

      if([firstChar isEqualToString:sectionChar]) 
      { 
       [sectionRowArray addObject:theStation]; 

       i++; 
      } 

      [firstChar release]; 
     } 

     if(i > 0) 
     { 
      [sectionSubArray addObject:sectionRowArray]; 
      [sectionTempArray addObject:sectionChar]; 
     } 

     [sectionRowArray release]; 
    } 

    self.sectionArray = sectionTempArray; 
    [sectionTempArray release]; 

    [theTable reloadData]; 
    theTable.scrollEnabled = YES; 
    [stationsXml release]; 

    locationManager = [[CLLocationManager alloc] init]; 
    locationManager.delegate=self; 
    locationManager.desiredAccuracy=kCLLocationAccuracyBest; 

    [locationManager startUpdatingLocation]; 
} 

我做的愚蠢的事情是,我環路經過我的300對象的每一封信我的陣列。但我找不到一個更好的方法來做到這一點。

最好的問候,
保羅Peelen

--------結果--------
這是個什麼結果變成了,感謝所有的答案:

- (void)viewDidLoad{ 
    self.filteredListContent = [NSMutableArray array]; 

    UIBarButtonItem *rightBarButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSearch 
                        target:self 
                        action:@selector(searchBar:)]; 
    self.navigationItem.rightBarButtonItem = rightBarButton; 

    [rightBarButton release]; 

    UISearchBar *mySearchBar = [[UISearchBar alloc] init]; 
    mySearchBar.delegate = self; 
    [mySearchBar setAutocapitalizationType:UITextAutocapitalizationTypeNone]; 
    [mySearchBar sizeToFit]; 
    theTable.tableHeaderView = mySearchBar; 

    if (UIInterfaceOrientationLandscapeRight == [[UIDevice currentDevice] orientation] || 
     UIInterfaceOrientationLandscapeLeft == [[UIDevice currentDevice] orientation]) 
    { 
     theTable.tableHeaderView.frame = CGRectMake(0.f, 0.f, 480.f, 44.f); 
    } 
    else 
    { 
     theTable.tableHeaderView.frame = CGRectMake(0.f, 0.f, 320.f, 44.f); 
    } 

    searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:mySearchBar contentsController:self]; 
    [self setSearchDisplayController:searchDisplayController]; 
    [searchDisplayController setDelegate:self]; 
    [searchDisplayController setSearchResultsDataSource:self]; 

    [mySearchBar release]; 

    /* Set the data */ 
    NSArray *stationenPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *stationenDocumentsDirectory = [stationenPath objectAtIndex:0]; 
    NSString *path = [stationenDocumentsDirectory stringByAppendingPathComponent:@"stations.plist"]; 

    NSDictionary* stationenDictionary = [[[NSDictionary alloc] initWithContentsOfFile:path] autorelease]; 
    xmlStationenList* stationsXml = [[xmlStationenList alloc] initWithDictionary:stationenDictionary]; 

    NSSortDescriptor *stationSorter = [[NSSortDescriptor alloc] initWithKey:@"_station" ascending:YES]; 
    NSMutableArray *xmlResult = [stationsXml getTimeResult]; 

    NSArray *objects = [[[NSArray alloc] initWithObjects:stationSorter,nil] autorelease]; 
    [xmlResult sortUsingDescriptors:objects]; 

    [stationSorter release]; 

    /* prefName is decided by the page opening chooseStationViewController. Using this class init function */ 
    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; 
    self.prefValue = [prefs valueForKey:prefName]; 

    self.listContent = [NSMutableArray array]; 

    for (stationenListSet *theList in xmlResult) 
    { 
     [self.listContent addObject:[theList get_station]]; 
    } 
    /* END set the data */ 

    /* Set sections */ 
    self.sectionArray = [[NSArray alloc] initWithObjects:@"-", @"A", @"B", @"C", @"D", @"E", @"F", @"G", @"H", @"I", @"J", @"K", @"L", @"M", @"N", @"O", @"P", @"Q", @"R", @"S", @"T", @"U", @"V", @"W", @"X", @"Y", @"Z", @"Å", @"Ä", @"Ö", nil]; 

    NSMutableDictionary *sectionDictionary = [NSMutableDictionary dictionaryWithObjectsAndKeys: 
               [[NSMutableArray alloc] init], @"-", 
               [[NSMutableArray alloc] init], @"A", 
               [[NSMutableArray alloc] init], @"B", 
               [[NSMutableArray alloc] init], @"C", 
               [[NSMutableArray alloc] init], @"D", 
               [[NSMutableArray alloc] init], @"E", 
               [[NSMutableArray alloc] init], @"F", 
               [[NSMutableArray alloc] init], @"G", 
               [[NSMutableArray alloc] init], @"H", 
               [[NSMutableArray alloc] init], @"I", 
               [[NSMutableArray alloc] init], @"J", 
               [[NSMutableArray alloc] init], @"K", 
               [[NSMutableArray alloc] init], @"L", 
               [[NSMutableArray alloc] init], @"M", 
               [[NSMutableArray alloc] init], @"N", 
               [[NSMutableArray alloc] init], @"O", 
               [[NSMutableArray alloc] init], @"P", 
               [[NSMutableArray alloc] init], @"Q", 
               [[NSMutableArray alloc] init], @"R", 
               [[NSMutableArray alloc] init], @"S", 
               [[NSMutableArray alloc] init], @"T", 
               [[NSMutableArray alloc] init], @"U", 
               [[NSMutableArray alloc] init], @"V", 
               [[NSMutableArray alloc] init], @"W", 
               [[NSMutableArray alloc] init], @"X", 
               [[NSMutableArray alloc] init], @"Y", 
               [[NSMutableArray alloc] init], @"Z", 
               [[NSMutableArray alloc] init], @"Å", 
               [[NSMutableArray alloc] init], @"Ä", 
               [[NSMutableArray alloc] init], @"Ö", nil]; 

    [sectionSubArray release]; 
    sectionSubArray = [[NSMutableArray alloc] init]; 

    for(NSString *theStation in listContent) { 
     NSString *firstChar = [[[NSString alloc] initWithFormat:@"%C", toupper([theStation characterAtIndex:0])] uppercaseString]; 

     [[sectionDictionary objectForKey:firstChar] addObject:theStation]; 
    } 

    NSArray *keys = [sectionDictionary allKeys]; 
    keys = [keys sortedArrayUsingSelector:@selector(localizedCompare:)]; 

    int indexPath = 0; 

    NSMutableArray *sectionTempArray = [[NSMutableArray alloc] init]; 

    [sectionTempArray addObject:@"-"]; 
    [sectionSubArray addObject:[[NSArray alloc] init]]; 

    for(NSString *key in keys) 
    { 
     if ([[sectionDictionary objectForKey:key] count] > 0) 
     { 
      NSArray *subArray = [[sectionDictionary objectForKey:key] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)]; 

      [sectionTempArray addObject:key]; 
      [sectionSubArray addObject:subArray]; 
     } 

     indexPath++; 
    } 

    self.sectionArray = sectionTempArray; 
    [sectionTempArray release]; 

    [theTable reloadData]; 
    theTable.scrollEnabled = YES; 
    [stationsXml release]; 

    locationManager = [[CLLocationManager alloc] init]; 
    locationManager.delegate=self; 
    locationManager.desiredAccuracy=kCLLocationAccuracyBest; 

    [locationManager startUpdatingLocation]; 
} 
+4

在站上循環並將它們添加到適當的字母桶中。應該快26倍。 – mvds 2011-01-11 00:30:34

+0

我在回答這個問題時提出了這個問題,但以防萬一:C語言風格的數組語法是什麼?這甚至在NSArrays上工作嗎?爲什麼不使用類的標準Objective-C方法,比如`NSMutableArray * sectionRowArrays = [NSMutableArray initWithCapacity:29]`,和[[SectionRowArrays objectAtIndex:index] addObject:theStation]`等等? – 2011-01-11 10:45:13

回答

2

這是帶有fiew變化的代碼。這是我所做的更改:

1)你有沒有留下一些代碼某處出使用局部變量,而不是裝載sectionArray 26倍
2)遍歷站一次,而不是29倍

? sectionSubArray未在此函數中定義,但似乎是局部變量。它也從未被分配到一個財產。

- (void)viewDidLoad{ 
    self.filteredListContent = [NSMutableArray array]; 

    UIBarButtonItem *rightBarButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSearch 
                       target:self 
                       action:@selector(searchBar:)]; 
    self.navigationItem.rightBarButtonItem = rightBarButton; 

    [rightBarButton release]; 

    UISearchBar *mySearchBar = [[UISearchBar alloc] init]; 
    mySearchBar.delegate = self; 
    [mySearchBar setAutocapitalizationType:UITextAutocapitalizationTypeNone]; 
    [mySearchBar sizeToFit]; 
    theTable.tableHeaderView = mySearchBar; 

    if (UIInterfaceOrientationLandscapeRight == [[UIDevice currentDevice] orientation] || 
    UIInterfaceOrientationLandscapeLeft == [[UIDevice currentDevice] orientation]) 
    { 
     theTable.tableHeaderView.frame = CGRectMake(0.f, 0.f, 480.f, 44.f); 
    } 
    else 
    { 
     theTable.tableHeaderView.frame = CGRectMake(0.f, 0.f, 320.f, 44.f); 
    } 

    searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:mySearchBar contentsController:self]; 
    [self setSearchDisplayController:searchDisplayController]; 
    [searchDisplayController setDelegate:self]; 
    [searchDisplayController setSearchResultsDataSource:self]; 

    [mySearchBar release]; 

    /* Set the data */ 
    NSArray *stationenPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *stationenDocumentsDirectory = [stationenPath objectAtIndex:0]; 
    NSString *path = [stationenDocumentsDirectory stringByAppendingPathComponent:@"stations.plist"]; 

    NSDictionary* stationenDictionary = [[[NSDictionary alloc] initWithContentsOfFile:path] autorelease]; 
    xmlStationenList* stationsXml = [[xmlStationenList alloc] initWithDictionary:stationenDictionary]; 

    NSSortDescriptor *stationSorter = [[NSSortDescriptor alloc] initWithKey:@"_station" ascending:YES]; 
    NSMutableArray *xmlResult = [stationsXml getTimeResult]; 

    NSArray *objects = [[[NSArray alloc] initWithObjects:stationSorter,nil] autorelease]; 
    [xmlResult sortUsingDescriptors:objects]; 

    [stationSorter release]; 

    /* prefName is decided by the page opening chooseStationViewController. Using this class init function */ 
    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; 
    self.prefValue = [prefs valueForKey:prefName]; 

    self.listContent = [NSMutableArray array]; 

    for (stationenListSet *theList in xmlResult) 
    { 
     [self.listContent addObject:[theList get_station]]; 
    } 
    /* END set the data */ 

    /* Set sections */ 
    NSMutableArray *sectionTempArray = [NSMutableArray array]; 
    self.sectionArray = sectionTempArray; 
    [sectionTempArray addObject:@"-"]; 
    [sectionTempArray addObject:@"A"]; 
    [sectionTempArray addObject:@"B"]; 
    [sectionTempArray addObject:@"C"]; 
    [sectionTempArray addObject:@"D"]; 
    [sectionTempArray addObject:@"E"]; 
    [sectionTempArray addObject:@"F"]; 
    [sectionTempArray addObject:@"G"]; 
    [sectionTempArray addObject:@"H"]; 
    [sectionTempArray addObject:@"I"]; 
    [sectionTempArray addObject:@"J"]; 
    [sectionTempArray addObject:@"K"]; 
    [sectionTempArray addObject:@"L"]; 
    [sectionTempArray addObject:@"M"]; 
    [sectionTempArray addObject:@"N"]; 
    [sectionTempArray addObject:@"O"]; 
    [sectionTempArray addObject:@"P"]; 
    [sectionTempArray addObject:@"Q"]; 
    [sectionTempArray addObject:@"R"]; 
    [sectionTempArray addObject:@"S"]; 
    [sectionTempArray addObject:@"T"]; 
    [sectionTempArray addObject:@"U"]; 
    [sectionTempArray addObject:@"V"]; 
    [sectionTempArray addObject:@"W"]; 
    [sectionTempArray addObject:@"X"]; 
    [sectionTempArray addObject:@"Y"]; 
    [sectionTempArray addObject:@"Z"]; 
    [sectionTempArray addObject:@"Å"]; 
    [sectionTempArray addObject:@"Ä"]; 
    [sectionTempArray addObject:@"Ö"]; 

    [sectionSubArray release]; 
    sectionSubArray = [[NSMutableArray alloc] init]; 
    sectionTempArray = [[NSMutableArray alloc] init]; 

    [sectionTempArray addObject:@"-"]; 
    [sectionSubArray addObject:[[NSArray alloc] init]]; 

    NSMutableArray *sectionRowArrays[29]; 
    memset(sectionRowArrays,0,sizeof(NSMutableArray*)*29); 
    for(NSString *theStation in listContent) { 
     char currChar = toupper([theStation characterAtIndex:0]); 
     uint8_t index; 
     if(currChar == 'Å') index = 26; 
      else if(currChar == 'Ä') index = 27; 
      else if(currChar == 'Ö') index = 28; 
      else index = currChar - 'A'; 
     if(!sectionRowArrays[index]) sectionRowArrays[index] = [[NSMutableArray alloc] init]; 
     [sectionRowArrays[index] addObject:theStation]; 
    } 
    for(uint8_t index = 0; index < 29; ++index) { 
     if(sectionRowArrays[index]) { 
      [sectionSubArray addObject:sectionRowArrays[index]]; 
      NSString *currChar; 
      if(index == 26) currChar = @"Å"; 
       else if(index == 27) currChar = @"Ä"; 
       else if(index == 28) currChar = @"Ö"; 
       else currChar = [NSString stringWithFormat:@"%c",index+'A']; 
      [sectionTempArray addObject:currChar]; 
      [sectionRowArrays[index] release]; 
     } 
    } 

    self.sectionArray = sectionTempArray; 
    [sectionTempArray release]; 

    [theTable reloadData]; 
    theTable.scrollEnabled = YES; 
    [stationsXml release]; 

    locationManager = [[CLLocationManager alloc] init]; 
    locationManager.delegate=self; 
    locationManager.desiredAccuracy=kCLLocationAccuracyBest; 

    [locationManager startUpdatingLocation]; 
} 
+0

嗨,thnx。一個問題雖然...錯誤在memset(charCounts,0,sizeof(NSMutableArray *)* 29); 「錯誤:'charCounts'未聲明(首次在此函數中使用)」= S – 2011-01-11 08:44:53

1

如何遍歷站列表並簡單地將每個添加到適當的「桶」?

如果你不需要NSObject和NSArrays,那麼你可以考慮使用標準模板庫'map <>模板。但是,如果你不熟悉這一點,那麼它可能會引入更多的複雜性(在學習曲線方面),而不是它的價值。

簡而言之,如何使用NSString鍵作爲第一個字母和對象是NSMutableArrays的NSMutableDictionary。

我沒有這樣做 - 但它會降低你的30x300迭代下降到300

1

你需要,如果你想花時間來提高代碼,需要一定的時間來分析您的應用程序的執行。

提示1:使用單字符在這裏,這將節省分配的數百或數千個:

NSString *firstChar = [[NSString alloc] initWithFormat:@"%C", toupper([theStation characterAtIndex:0])]; 

提示2:你的一些藏品在使用增量增長填充。這將有助於儘可能減少增長/重新分配的數量。蘋果第二次已經猜到了你,所以他們的優化基於現實世界的使用,有時候會對你有利,但不是所有的時候都可能。如果您在人口中過度分配收藏,則可以通過創建副本然後處置臨時圖來將其平鋪。

提示3:儘可能避免自動釋放對象。 (嚴重)

當然,你也想要優化你的搜索/排序/填充算法。

但嚴重的是,如果您想了解您的時間花費在哪裏,則必須進行配置。

祝你好運!

+1

+1大提示。我想重申提示3:只有在實際上沒有其他選擇的情況下才使用autorelease。在不再需要它的時候自行釋放它將減少總內存使用量和(在較小程度上)CPU負載。 – 2011-01-11 02:55:40

1

到其他的答案就增加,因爲這是一個非常小的事情,是不是幾乎一樣重要的事,但你至少應該知道。

此:

NSMutableArray *sectionTempArray = [NSMutableArray array]; 
self.sectionArray = sectionTempArray; 
[sectionTempArray addObject:@"-"]; 
[sectionTempArray addObject:@"A"]; 
[sectionTempArray addObject:@"B"]; 
[sectionTempArray addObject:@"C"]; 
[sectionTempArray addObject:@"D"]; 
[sectionTempArray addObject:@"E"]; 
[sectionTempArray addObject:@"F"]; 
[sectionTempArray addObject:@"G"]; 
[sectionTempArray addObject:@"H"]; 
[sectionTempArray addObject:@"I"]; 
[sectionTempArray addObject:@"J"]; 
[sectionTempArray addObject:@"K"]; 
[sectionTempArray addObject:@"L"]; 
[sectionTempArray addObject:@"M"]; 
[sectionTempArray addObject:@"N"]; 
[sectionTempArray addObject:@"O"]; 
[sectionTempArray addObject:@"P"]; 
[sectionTempArray addObject:@"Q"]; 
[sectionTempArray addObject:@"R"]; 
[sectionTempArray addObject:@"S"]; 
[sectionTempArray addObject:@"T"]; 
[sectionTempArray addObject:@"U"]; 
[sectionTempArray addObject:@"V"]; 
[sectionTempArray addObject:@"W"]; 
[sectionTempArray addObject:@"X"]; 
[sectionTempArray addObject:@"Y"]; 
[sectionTempArray addObject:@"Z"]; 
[sectionTempArray addObject:@"Å"]; 
[sectionTempArray addObject:@"Ä"]; 
[sectionTempArray addObject:@"Ö"]; 

可與此替換:

NSArray sectionTempArray = [[NSArray alloc] initWithObjects: @"-", @"A", @"B", 
    @"C", @"D", @"E", @"F", @"G", @"H", @"I", @"J", @"K", @"L", @"M", @"N", 
    @"O", @"P", @"Q", @"R", @"S", @"T", @"U", @"V", @"W", @"X", @"Y", @"Z", 
    @"Å", @"Ä", @"Ö", nil]; 

消除用於可變數組的需要(減少開銷)和,如果編譯器不會優化掉那些30 ADDOBJECT電話,加快了一點。如果在初始化後不需要更改NSArray(或NSString或NSDictionary等)的內容,請不要使用Mutable版本(如果可以的話)。