Share
Hi,
if you like to use assertions in your source code, but you miss this feature in ObjectiveC, give a look to this small class.
Assert.h
#import <Foundation/Foundation.h>
@interface Assert : NSObject {
}
+(void)that:(BOOL)expr;
@end
Assert.m
#import "Assert.h"
@implementation Assert
+(void)that:(BOOL)expr{
if (!expr) {
[NSException raise:@"Failed assertion." format:@"Failed assertion", nil];
}
}
@end
As you can see, there’s only one static method that you can use wherever you want.
In this [...]
Share
This is a small snippet, useful whenever you want to convert a floating point number in a string with a fixed number of decimal digits.
NSNumberFormatter *format = [NSNumberFormatter new];
[format setMaximumFractionDigits:1];
NSNumber *aNumber = [[NSNumber alloc ] initWithDouble:54.4235264];
NSString label = [[NSString alloc] initWithFormat:@”The number is %@”, [format stringForObjectValue:aNumber]];
[distance release];
[format release];
Obviously the NSNumberFormatter [...]
Share
I’m working to an iPhone application with a TabBar on the footer area. Among the others there are a “Home” button and an “Account” button. The first allows the user to see a view that gives an overview of the application. The latter shows the view that the user uses to manage his/her account.
If the [...]
How to implement a read-only computed property in [...]