5

i am getting the error:expected a type in xcode.I don't know why i am getting this kind of error in my .h class. here is my code and screen shot.

#import <Foundation/Foundation.h>
@interface NaviGationStack : NSObject
@property (nonatomic, strong) NSMutableArray *navigattionStack;
+(NaviGationStack*)navigationStackClass;
-(void)popViecontrollerFromStack;
-(int)getNumberElementInStack;
-(void)pushViewControllerToStack:(UIViewController *)viewController;

i am getting this error in last function.here is the error

ankyy
  • 351
  • 6
  • 16

1 Answers1

16

Import UIKit.h rather than Framework.h:

#import <UIKit/UIKit.h>
trojanfoe
  • 120,358
  • 21
  • 212
  • 242
  • 1
    Should not be necessary. Most header files do not import UIKit. In fact, he shouldn't have to import anything; the _.pch_ file imports both UIKit and Foundation. In fact, I copied and pasted his code into my project and _deleted_ the `#import` line, and it still compiles just fine. Something else is going on here. – matt Jan 11 '14 at 21:00
  • @matt So you're saying that all source and header files use the pre-compiled header even if they don't `#import Prefix.pch`? – trojanfoe Jan 13 '14 at 07:14
  • Yes, that is what a pre-compiled header _is_. – matt Jan 13 '14 at 19:13
  • @matt What do you mean, that is what a pre-compiled header *is*? That makes no sense. What it *is* is a mechanism to speed-up include files, but normally there is an elective part where a source/header file includes the pre-compiled header (think `stdafx.h` in MFC). It looks to be the same with Xcode. – trojanfoe Jan 14 '14 at 06:29
  • What I mean by "is" is that, as Aristotle would say, this is the "what it is to be" of a precompiled header. The precompiled header is a "prefix file". It is _implicitly_ included by _all_ source files. That is _why_ it is precompiled. - Try it yourself. Do a #define in the .pch file, and refer to it in any source file. You'll see that it works. Alternatively, delete all #import of UIKit and Foundation from your .h files. Your code still compiles, because everything imports the .pch file, which imports UIKit and Foundation. – matt Jan 14 '14 at 16:12
  • @matt So I guess the reason my answer has solved the OPs question is that he must have messed-up the pre-compiled headers in his project. That is, if it actually did answer his question (it wouldn't be the first time that someone just accepted any old crap answer). – trojanfoe Jan 14 '14 at 16:14
  • Right, that's why I asserted that "something else is going on here" in my first comment. But we will never know what it is. From his screen shot, it looks like he has migrated old code (note the source code creation date) into a new Xcode 5 / iOS 7 template (note the asset catalog, test target files, etc.). Something presumably went wrong in that process. – matt Jan 14 '14 at 17:08
  • Perfect, had the same problem and solved it!!! – Alex Cio Jan 24 '14 at 10:29
  • In Xcode 6 beta, I was getting this issue with my bridging header. This solution worked for me. – Jon Aug 05 '14 at 22:19