diogo.appDev diogo.appDev - 1 month ago 16
Objective-C Question

iOS 8 Expected a type

I have the

UIScrollViewSlidingPages
and the
SSPullToRefresh
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

-(id)initWithHeaderText:(NSString*)headerText;
-(id)initWithHeaderImage:(UIImage*)headerImage;

//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;

@end


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

-(id)initWithHeaderImage:(UIImage*)headerImage;


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

@property(strong, nonatomic) UIImage *headerImage;

Answer

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.

Comments