Strange error regarding instance variables and superclass

I have a code in which my classes are inherited from a superclass, and everything still works. I get an error whenever I try to use any of the superclass variables saying that they are not declared (use in this function first). This only happens in one of my subclasses, and it looks exactly like the others. I am wondering if there is something obvious that I should know about (being completely new to Objective-C). The main code is similar -

@interface mySuperClass : UIViewController { BOOL myVar; } 

Then -

 @interface mySubClass : mySuperClass { } @implementation mySubClass { -(void)someMethod { myVar = YES; // error here } @end 

Any help is greatly appreciated - if you need more information let me know! Thanks.

+7
source share
4 answers

I just got a very similar weird error when I could no longer access the properties in my superclass, and xcode is a givine to me compiler of errors saying "(*) undeclared (first use in this function)". However, in the past I had no problems ...

The problem was that I introduced typos at the top of my .m file, and the output of the xcode compiler was misleading to me. In particular, I had @synthesize operators in which the properties were written with an error, either in the synthesis expression or in the corresponding variable in the header file.

If you have @synthesize operators or other declarations, examine them with a thin jagged comb (i.e., what lines do you enter recently?) Or even comment out a block of them to see if you can compile and narrow down the culprit again .

Again, compiler errors were very misleading, so it was very difficult to debug. Although, like 99.9% of cases, the error was mine. :)

+4
source

I do not see anything wrong with the code you pasted. My first assumption was that you are not importing the mySuperClass.h file properly. Those. you are lacking

 #import "mySuperClass.h" //or #include 

In mySubClass.h or mySubClass.m

+2
source

I ran into the same problem, and after spending a lot of time, I finally solved it in my project:

I reorganized my source and deleted the member, but forgot to remove the @property definition in the .h file. This leads to errors in every place when I use super members. BTW: Ways from the super are fine.

So check your defs properties. Thanks to Screwtape in post 8 for solving it :-)

EDIT: Unfortunately, Chris's answer is pretty similar except from typos or deletions.

+1
source

I have the same problem for weeks

"Variable Undeclared" error while compiling on iOS device, but not for Simulator

One of the solutions I found is to simply change the compiler from the standard LLVM GCC 4.2 to LLVM Compiler 2.0 (or to `Apple LLVM Compiler 2.1). This seems to be a bug in the compiler, but this is just an assumption.

Change is a quick fix for your problem if you don't need to use the GCC compiler at all.

+1
source

All Articles