Tag: variables

What's the meaning of static variables in an implementation of an interface?

I don’t quite understand static variables when defined in the implementation of an interface. In methods I do understand how they differ from local variables, but not when defined directly in an implementation. Look at these examples. What difference do these two make practically? #include “MyClass.h” @implementation MyClass int myInt; … @end And: #include “MyClass.h” […]

Is it necessary to assign a string to a variable before comparing it to another?

I want to compare the value of an NSString to the string “Wrong”. Here is my code: NSString *wrongTxt = [[NSString alloc] initWithFormat:@”Wrong”]; if( [statusString isEqualToString:wrongTxt] ){ doSomething; } Do I really have to create an NSString for “Wrong”? Also, can I compare the value of a UILabel‘s text to a string without assigning the […]

How to define a global variable that can be accessed anywhere in my application?

Possible Duplicate: Global int variable objective c I would like to create a global variable. I want to access to this variable anywhere. The Java equivalent: static var score:int = 0; For example if I define a global variables into the Game class. How to access to this global variable? Game.score ?

Declaring variables inside a switch statement

This question already has an answer here: Why can't variables be declared in a switch statement? 23 answers

Objective C Static Class Level variables

I have a class Film, each of which stores a unique ID. In C#, Java etc I can define a static int currentID and each time i set the ID i can increase the currentID and the change occurs at the class level not object level. Can this be done in Objective C? I’ve found […]

Create multiple numbered variables based on a int

How would I create a number of NSDictionary variables using an array’s count? This is basically what I came up with, but I’m not sure how to make this work with Objective-C syntax. doesntContainAnother is an NSArray. I want the names of the dictionaries to use the current value of loopInt. int *loopInt = 0; […]

How does an underscore in front of a variable in a cocoa objective-c class work?

I’ve seen in a few iPhone examples that attributes have used an underscore _ in front of the variable. Does anyone know what this means? Or how it works? An interface file I’m using looks like: @interface MissionCell : UITableViewCell { Mission *_mission; UILabel *_missionName; } @property (nonatomic, retain) UILabel *missionName; – (Mission *)mission; I’m […]

can variables be set randomly when declaring them again?

In my method, I declare some variables, including int blockCount;. I call this method more than once. Using the Xcode debugger, I found out that after the second time the method was called, the value of blockCount was set to 364265, while it was set to 2, just a few milliseconds earlier. It’s not a […]

Save variable after my app closes (swift)

I’m trying to save a variable in Xcode so that it saves even after the app has closed, how ever when I access it I do it from a several different classes and files, and I change the value of the variable when I access it. Therefore similar threads do not completely apply, the value […]

Why is Xcode's Variables View's “Edit Value” not changing the variable value?

In Xcode’s Variables View, on the right of the Debug area, when an app is running and paused at a breakpoint you can right-click a variable and select “Edit Value”. For a swift String it’s greyed out, and I can imagine why that might be the case. But even for a simple int, it brings […]