user1625435
user1625435

Reputation: 153

#define SIZEOF Xcode

I have an Xcode project, and in my UIView.h I have this like of code:

#define FINGER_SIZE 20

Tell me please, how can I change the value of FINGER_SIZE, from another UIView.

I have SecondView, and UIButton. I need something like:

    -(IBAction)changeSize
{

//Change FINGER_SIZE from 20 to 50

}

The "changeSize" action I have in my SecondView, and #define FINGER_SIZE 20, I have in UIView.h

Thank you.

Upvotes: 1

Views: 135

Answers (1)

Sergey Kalinichenko
Sergey Kalinichenko

Reputation: 726639

The #define preprocessor construct does not define a variable, it defines a constant. It is not possible to change the value of FINGER_SIZE, because it does not exist by the time the Objective C compiler starts looking at your code: it's replaced by 20 by then.

What you are looking for is a global variable. Declare it in the header like this

extern NSUInteger FINGER_SIZE;

and then define it in a .m file like this:

NSUInteger FINGER_SIZE = 20;

Now you have an assignable variable that you can change freely from any method that sees the declaration.

Upvotes: 5

Related Questions