2016-04-15 3 views
1
+ (NSDateFormatter *) formatter : (NSString *) format : (NSTimeZone*) timeZone : (NSLocale *) locale { 
    format = DefaultFormat; 
    timeZone = [NSTimeZone localTimeZone]; 
    locale = [NSLocale currentLocale]; 
    NSString *hashKey = [NSString stringWithFormat:@"%lu%lu%lu", (unsigned long)format.hash, (unsigned long)timeZone.hash, (unsigned long)locale.hash]; 
    NSDictionary *formatters = [NSDate sharedDateFormatters]; 
    NSDateFormatter *cachedDateFormatter = formatters[hashKey]; 
    if (cachedDateFormatter != nil) { 
     return cachedDateFormatter; 
    } 
    else { 
     NSDateFormatter *formatter = [[NSDateFormatter alloc]init]; 
     formatter.dateFormat = format; 
     formatter.timeZone = timeZone; 
     formatter.locale = locale; 
     formatters[hashKey] = formatter; 
     return formatter; 
    } 

} 

NSDictionaryの*」予想方法は、型のオブジェクトに見つからない「NSDictionaryの*」

もっとコンテキスト:

+ (NSMutableDictionary<NSString *, NSDateFormatter *>*)sharedDateFormatters { 
    static NSMutableDictionary *dict = nil; 
    static dispatch_once_t onceToken; 
    dispatch_once(&onceToken, ^{ 
     dict = [NSMutableDictionary new]; 
    }); 
    return dict; 
} 

答えて

0

それは不変だとしてあなたはNSDictionaryオブジェクトを更新することはできません。

EDITsharedDateFormattersはどこから来るのかを示すので:それはどのようなクラスメソッドの戻りだ、と、コードが正しく動作しますよう

あなたは、単に、代わりにNSDictionaryNSMutableDictionaryformattersを行う必要があります。

NSMutableDictionary *formatters = [NSDate sharedDateFormatters]; 
+0

あなたは何をアドバイスしますか?私は迅速なライブラリをObjective-Cに変換しています。 –

+0

'sharedDateFormatters'の出所は、標準の' NSDate'クラスの一部ではないので、あなたに教えてください。 – trojanfoe

+0

質問が編集されました。 –

関連する問題