iOS 6.1
に対処するコードをいくつか開発しましたNSError
。しかし、私はそれに満足していません。それはせいぜいハックです:
-(bool) reptErrAtModule: (NSString *) module
atSubr: (NSString *) subr
atFunc: (NSString *) func
withErr: (NSError *) err
{
id value = [[err userInfo] objectForKey: NSUnderlyingErrorKey];
NSString * errDesc = (value != nil) ?
[value localizedDescription]:
(NSString *)[[err userInfo] objectForKey: @"reason"];
NSLog( @"ERR -> %@",[NSString stringWithFormat:
@"(%@>%@) %@ failed! %@",module,subr,func,errDesc] );
}
より単純なフォーム ((NSString *)[[err userInfo] objectForKey: @"reason"]
大文字と小文字を区別しない) があり、 への呼び出しから返されたエラーに対して機能しましたremoveItemAtPath
。
しかし、その後、このコードからエラーが返されました:
NSPersistentStore * entStor =
[myPerStoCor addPersistentStoreWithType: NSSQLiteStoreType
configuration: nil
URL: [NSURL fileURLWithPath: Path]
options: nil
error: &err];
そして、私のルーチンはエラーを抽出できませんでした。@"reason"
デバッガーの Info データに必要なテキストが表示されたので、ロジックを追加しました。
現在、コードは両方のタイプのエラーで機能しますが、これはこれを行う方法ではないと考えています。システムが返す可能性のあるすべてのタイプのエラーに対処するための、より優れた、より一般的な方法が必要ですNSError
。