Re: Bindings crash
Re: Bindings crash
- Subject: Re: Bindings crash
- From: Ken Thomases <email@hidden>
- Date: Thu, 26 Jan 2012 09:23:58 -0600
On Jan 26, 2012, at 4:12 AM, Arved von Brasch wrote:
> - (NSString *)usedSpace {
> NSDictionary *systemInfo = [[NSFileManager defaultManager] attributesOfFileSystemForPath: [[NSBundle mainBundle] bundlePath] error: nil];
> NSDecimalNumber *total = [NSDecimalNumber decimalNumberWithString: [[systemInfo objectForKey: NSFileSystemSize] stringValue]];
> NSDecimalNumber *avail = [NSDecimalNumber decimalNumberWithString: [[systemInfo objectForKey: NSFileSystemFreeSize] stringValue]];
> return [self humanReadableNumber: [total decimalNumberBySubtracting: avail]];
> }
First, why are you using strings to convert to NSDecimalNumber? Ask the NSNumber for its decimalValue and then use +[NSDecimalNumber decimalNumberWithDecimal:]. That avoids formatting and parsing of strings.
Second, why do you need NSDecimalNumber? Can you not use either unsigned long long or double for this purpose?
> This problem seems to depend on the compilation order. Commenting out the offending code, recompiling, then restoring the code and recompiling makes the problem go away. Performing a Clean operation than recompiling makes the problem reappear. This suggests compilation order affects whether the systemInfo dictionary has valid elements or not at runtime.
I doubt that. Probably, you have an uninitialized variable or stack smashing bug somewhere and the compilation order affects the layout of the stack which changes either what garbage is in the uninitialized variable or what on the stack gets smashed.
Certainly, you can log the values you get from systemInfo to check your hypothesis.
> As to why @dynamic is there, I thought that was the proper way to implement a property where the implementation was supplied by me rather than synthesised. Is that not the case?
You don't need @dynamic for properties where you supply the accessors at compilation time. It's only necessary for when the accessors aren't apparently available but will be at runtime. For example, by dynamically loading a category or self-modifying code. (NSManagedObject uses something like the latter.)
Regards,
Ken
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden