2016-09-06 14 views
1

Objective-C(OS X 10.9)では、ファイルにNSDictionaryを[MyDict writeToFile:SavePath atomically:YES];で書き込みます。 MyDict = [NSDictionary dictionaryWithContentsOfFile:filePath];NSCalendarDateをxmlファイルに変換して返します。__NSTaggedDate

で辞書を復元します。しかし、NSCalendarDateのオブジェクトを含むキーがNSCalendarDateでなく、__NSTaggedDateであることに遭遇しました。コードの行で

2016-09-06 09:19:39.957 MyProject[720:303] -[__NSTaggedDate yearOfCommonEra]: unrecognized selector sent to instance 0x41bd7801f000000d 

:これは私に次のエラーを与える

if([AtTansaction.TransactionDate yearOfCommonEra] == DataArray[cnt].year) 

NSCalendarDateを再構築するために、どのように? NSTaggedDateとは何ですか?

+0

NSCalendarDateという名前のクラスを正確に見つけましたか? iOS apiにありますか?おそらくあなたはNSDateについて言及しようとしています。あなたは本当にNSTaggedDateが何であるか気にする必要はありません。それはクラスの内部表現かもしれません。 – Sandeep

+0

@Sandeep OS Xでタグ付けされた 'NSCalendarDate'は' NSDate'から継承しています。 – Larme

+0

'NSCalendarDate'は推奨されていません。 * NSCalendarDateの使用を強くお勧めします。 カレンダー計算の場合は、NSCalendar、NSDate、およびNSDateComponentsの適切な組み合わせを で使用する必要があります(日付と時刻のカレンダー、Cocoa * – vadian

答えて

0

OK、間違いを発見しました。 NSDictionaryはを保存するだけで、NSCalendarDateではなく保存します。返されるオブジェクトは、NSDateから継承された__NSTaggedDateです。物体上DumpObjcMethods(object_getClass(_StartDate))とそのスーパークラス:

Found 9 methods on '__NSTaggedDate' 
'__NSTaggedDate' has method named 'dealloc' of encoding '[email protected]:8' 
'__NSTaggedDate' has method named 'timeIntervalSinceReferenceDate' of encoding '[email protected]:8' 
'__NSTaggedDate' has method named 'initWithTimeIntervalSinceReferenceDate:' of encoding '@[email protected]:8d16' 
'__NSTaggedDate' has method named 'isInToday' of encoding '[email protected]:8' 
'__NSTaggedDate' has method named 'isInTomorrow' of encoding '[email protected]:8' 
'__NSTaggedDate' has method named 'isInYesterday' of encoding '[email protected]:8' 
'__NSTaggedDate' has method named 'isInSameDayAsDate:' of encoding '[email protected]:[email protected]' 
'__NSTaggedDate' has method named 'isEqual:toUnitGranularity:' of encoding '[email protected]:[email protected]' 
'__NSTaggedDate' has method named 'compare:toUnitGranularity:' of encoding '[email protected]:[email protected]' 

幸いにも、私は_StartDate =でNSCalendarDateに(したがって__NSTaggedDateNSDate Sに変換することができ、私が呼び出すことによって、これを見つけた[NSCalendarDate dateWithTimeInterval:0 sinceDate:_StartDate]。

関連する問題