21

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;
Jagat Dave
  • 1,643
  • 3
  • 23
  • 30
diogo.appDev
  • 1,595
  • 5
  • 16
  • 30

1 Answers1

74

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.

Airsource Ltd
  • 32,379
  • 13
  • 71
  • 75
  • He should not need to do that -- it should already be set up if he doesn't muck with the defaults. (He shouldn't need to import Foundation either.) – Hot Licks Oct 16 '14 at 20:01
  • If you create a simple new project in XCode, it will add an import for UIKit in the app delegate/vc header files. (and, of course, nothing for Foundation, because as you say, it's not needed). So yes, he shouldn't need to do it, but he's presumably somewhat of the beaten track already. Maybe he's missing a pch. – Airsource Ltd Oct 16 '14 at 20:04
  • Tremendous help, thanks! We had all kinds of compile errors trying to use SSPullToRefresh in a Swift project, things like "UIView is an unknown type". We added UIKit to our bridging file and this resolved it! – Mike Taverne Feb 11 '15 at 19:19