Re: Category class method problem
Re: Category class method problem
- Subject: Re: Category class method problem
- From: Kaspar Fischer <email@hidden>
- Date: Thu, 9 Mar 2006 21:09:32 +0100
On 09.03.2006, at 20:36, Andy Lee wrote:
On Mar 9, 2006, at 2:26 PM, Kaspar Fischer wrote:
name = [NSString stringWithFormat:@"%@/%d-%d.%@", // (*)
[[NSProcessInfo processInfo] processIdentifier],
(int)[NSDate timeIntervalSinceReferenceDate],
sequenceNumber,
extension];
-processIdentifier returns an int, whereas your format string
expects an object. The crash occurs because -stringWithFormat:
tries to dereference an int as an object pointer.
Uuuh, shame on me, I am really sorry... This is more than trivial.
Thanks for the help, Andy!
Kaspar
P.S. The fixed code might be something like this:
+ (NSString *)nameOfTemporaryFileWithExtension:(NSString *)extension
{
static int sequenceNumber = 0;
NSString *tmpDir = NSTemporaryDirectory();
if (tmpDir == nil)
tmpDir = @"/tmp/";
NSString *name;
do {
sequenceNumber++;
name = [NSString stringWithFormat:@"%@/%@-%d-%d-%d.%@",
tmpDir, [[NSBundle mainBundle] bundleIdentifier],
[[NSProcessInfo processInfo] processIdentifier],
(int)[NSDate timeIntervalSinceReferenceDate],
sequenceNumber,
extension];
} while ([[NSFileManager defaultManager] fileExistsAtPath:name]);
return name;
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden