I have the following in my .h class:
extern CGFloat tableMarginSide;
extern CGFloat tableMarginTop;
extern CGFloat fromImageSize;
extern CGFloat keyboardHeightPortrait;
extern CGFloat keyboardHeightLandscape;
and in my init I did:
CGFloat tableMarginSide = 20;
CGFloat tableMarginTop = 20;
CGFloat fromImageSize = 50;
CGFloat keyboardHeightPortrait = 210;
CGFloat keyboardHeightLandscape = 160;
if (IS_IPAD){
CGFloat tableMarginSide = 80;
CGFloat tableMarginTop = 65;
CGFloat fromImageSize = 50;
CGFloat keyboardHeightPortrait = 260;
CGFloat keyboardHeightLandscape = 350;
}
Why is it that I am getting warnings and I can’t use this float in my class? Oh I don’t want to use preprocessor by the way
You’re re-decalring new variables with the same name in
init. Inside of theinitmethod, declaration are local to that block. What you mean is this:header
impl
That said, this is exactly the kind of problem that nib files and storyboards are designed to deal with.
Even without nib files, I would avoid this approach. It is very dependent on making sure that you call
initprior to accessing these globals (and it is very easy for this not to happen if you’re not very careful). A better approach is to create class or instance methods for these rather than create “pseudo-constants” (which aren’t really constant because they change at runtime).