NSTemporaryDirectory behavior changed in SDK 6

I had some code that looked like this to clear out the temp folder:

NSFileManager *fm = [NSFileManager defaultManager];

[fm removeItemAtPath:NSTemporaryDirectory() error:NULL];

[fm createDirectoryAtPath:NSTemporaryDirectory() withIntermediateDirectories:YES attributes:attr error:NULL];

 

This used to work. ┬áThe second call to NSTemporaryDirectory() now returns nil or /var/tmp or something equally different from my app’s temporary directory.

To fix, cache the value of NSTemporaryDirectory