0

申し訳ありませんが、これは初心者の質問かもしれませんが、私は CoreLocation で作業しており、これは困惑しています。

このサイトで推奨されているシングルトンを使用して currentLocation を検索しています。currentLocation オブジェクトを取得すると、not nil チェックに対して true が返されます。ただし、その説明を印刷しようとすると、EXC_BAD_ACCESS がスローされます。

//WORKS Current location 8.6602e-290
NSLog(@"Current location %g",currLoc);

//DOESN'T WORK
NSLog(@"Current location %@",[currLoc description]);

//DOESN'T WORK - Is this causing the description to fail as well?
NSLog(@"Current location %g",currLoc.coordinate.latitude);

最初のものでは何かが見えるのに、他のものでは見えないのはなぜですか? ところで、これは 3.1.2 シミュレーターで実行されています。ありがとうございます。

4

3 に答える 3

1

currLoc.coordinate.latitude は double 型です... %g が機能しない場合は %f を使用できます

NSLog(@"Current location %f",currLoc.coordinate.latitude);
于 2010-05-06T06:21:18.263 に答える
0

currLocは、 not Nil checkに対してTRUEを返している可能性があります。ただし、nil チェック条件を通過するオブジェクト (ダングリング ポインター) を解放する可能性があります。これはあなたの問題かもしれません。

currLoc メンバーを直接使用する代わりに、 currLoc のアクセサーを使用します。これで問題が解決します:)

于 2010-05-06T07:03:21.810 に答える
0
// malformed: %g format specifier expects type
// double, you're passing an objc object.
// sending arguments through (...) with the
// invalid types/widths is a near certain way
// to crash an app, and the data will be useless
// to the function called (NSLog in this case)
NSLog(@"Current location %g",currLoc);

// try running the app with zombies enabled.
// in short, enabling zombies (NSZombiesEnabled)
// is a debugging facility to determine whether
// you use an objc object which would have been freed.
NSLog(@"Current location %@",[currLoc description]);

// as long as currLoc is a pointer to a valid (non-freed)
// objc object, then this should be fine. if it is not valid
NSLog(@"Current location %g",currLoc.coordinate.latitude);
于 2010-05-06T07:33:09.697 に答える