I am working on an iphone app that has multiple view controllers. I'm currently able to pass an int value to and from the app delegate as follows (I want to use float instead!, but not sure how):
app delegate.h
@interface {
NSInteger accumulatedTime;
}
@property (nonatomic) NSInteger accumulatedTime;
@end
app delegate.m
@implementation
@synthesize accumulatedTime;
then in my view controller.h
@interface {
int secs2;
}
view controller.m
BetaTeam1AppDelegate *mainDelegate = (BetaTeam1AppDelegate *)[[UIApplication sharedApplication] delegate];
secs2 = mainDelegate.accumulatedTime ;
I want to use a float instead, Easy enough to change int to float in the view controllers .h and .m but how to code in the app delegate?
Upvotes: 0
Views: 1012
Reputation: 27601
Consider placing this global information in a different place, like a Model object in the MVC theme. Even if it's a Singleton, it's better design than filling up your App Delegate like this.
Upvotes: 0
Reputation: 299485
Just change the type of accumulatedTime
to float
. float
and int
are no different here; both are just C types, and properties can return C types.
That said, you should probably make accumulatedTime
be of type NSTimeInterval
, as this will be more consistent with Cocoa time routines. NSTimeInterval
is generally implemented as a double
.
Upvotes: 1
Reputation: 5266
NSNumber can encapsulate a CGFloat.
NSNumber *accumulatedTime;
CGFloat secs2 = [mainDelegate.accumulatedTime floatValue];
Upvotes: 0