2016-04-15 9 views
0
NSString *hashKey = [NSString stringWithFormat:@"%lu%lu%lu", (unsigned long)format.hash, (unsigned long)timeZone.hash, (unsigned long)locale.hash]; 
NSDateFormatter *formatters = [NSDate sharedDateFormatters]; 
NSDateFormatter *cachedDateFormatter = formatters[hashKey]; 

私はこのラインでトラブルを抱えています:予想方法「NSDateFormatter *」

NSDateFormatter *cachedDateFormatter = formatters[hashKey]; 

は私に語った:期待辞書要素を読み込むためのメソッドオブジェクトに見つかりませんタイプの "NSDateFormatter *"

いくつかのコンテキスト:

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

答えて

1

ごの戻り値の型は何ですか方法?

formatters変数を宣言したデータ型は何ですか?

切断を参照してください。彼らは一致する必要があります。 NSDateFormatterの変数にNSDictionaryの値を割り当てることはできません。

変更し、あなたの行に:

NSDictionary *formatters = [NSDate sharedDateFormatters]; 

か:

NSDictionary<NSString *, NSDateFormatter *> *formatters = [NSDate sharedDateFormatters];