diogo.appDev diogo.appDev - 1 year ago 154
Objective-C Question

iOS 8 Expected a type

I have the

and the
libraries in a lot of projects, but suddenly, I'm getting this weird errors in this new iOS 8 project.

#import <Foundation/Foundation.h>

@interface TTSlidingPageTitle : NSObject


//The title text to go in the nav bar
@property(strong, nonatomic) NSString *headerText;

//An image to use in the nav bar (if you set this, the title text will not be used)
@property(strong, nonatomic) UIImage *headerImage;


This line is getting the "Expected a Type" error:


And this line is getting the "Unknown type name UIImage" error:

@property(strong, nonatomic) UIImage *headerImage;

Answer Source

If you check the docs for UIImage you'll see it's in UIKit, not Foundation. The docs are now all targeted at Swift, which is somewhat annoying, but you'll see the import statement in the docs is specified as

@import UIKit;

which you need at the top of your file (no need for the Foundation import either).

Sometimes projects include this import statement in a precompiled header file (pch). This should be referenced in Build Settings->Prefix Header, or it won't be used in compilation.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download