Tag: declaration

Objective-c basics: Object declared in MyAppDelegate not accessible in another class

I have an object declared in my app delegate: @interface MyAppDelegate : NSObject <UIApplicationDelegate> { ClassName *className; } In another class, I include the app delegate: #import “MyAppDelegate.h” @implementation AnotherClass -(void)doMethod { [className doClassNameMethod]; } This fails at compile time due to className being undeclared. Shouldn’t it be accessible, since I’ve included the MyAppDelegate, where […]

Help with understanding C# code and porting to Objective-C

Ok, I have this prototype that was written by someone else in C# and I’m trying to put it into Objective-C. Now, I haven’t had any formal experience with C# yet, so I don’t know everything about it yet. I understand what the first three variables are, but I’m running into problems with what the […]

Where various variable and method types should be placed in a header

I’ve noticed that I get compilation errors if I place certain declarations in certain places in my header file. I’ve put comments into the code as to where I think certain things go; are they correct? @interface Level : CCNode { //Instance variables? PlayBackgroundLayer* playBGLayer; PlayUILayer* playUILayer; PlayElementLayer* playElementLayer; } //Static methods? +(void) InitLevel: (int) […]

Objective-C: How Can I Access String Variable As a Global?

I am new to iPhone development. I want to access a string variable in all the class methods, and I want to access that string globally. How can I do this? Please help me out.

How to Access String Variable in One View Controller to Another view Controller

I am new to iphone development, Now i want to access the string variable in all the view controller, but i know to declare the variables in delegate method, but i cant access it, please help me out. Mainviewcontroller–>Viewcontroller1_–>viewcontroller2–>viewcontroller3–>subwebview. i have created one main view controller and the subview class are Viewcontroller1,viewcontroller2,viewcontroller3. And the subwebview […]

Objective C: Why do we declare ivars in the .h member area if @property seems to do it automatically?

In implementing an interface it seems the common method in tutorials and literature is to declare an ivar and then set the @property then @synthesize. @interface MyClass : NSObject { NSString *myString; } @property (nonatomic, retain) NSString *myString; @end However, omitting the explicit declaration and just putting @property has the same effect. @interface MyClass: NSObject […]

When to use UIKIT_EXTERN vs just extern

I’m guessing I would only use UIKIT_EXTERN if there is a chance of C++ code in my project that may use the variable. If this is the case wouldn’t it just be safe to declare all your externally available constants with UIKIT_EXTERN? How come I don’t see this more?

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

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 […]

Synthesize error “Missing Context for Property Implementation Declaration”

Anyone have any ideas? When I try to synthesize a property I have declared in the .h file its not letting me synthesize it. Any ideas? Thanks!