17

I'm trying to add an objective C library for toasts to my xcode project. But I'm getting a number of these errors:

"Cannot find interface declaration for 'UIView'"

"Expected a type"

I have linked with the QuartzCore.framework. And the .m file has been added to compile sources. What am I missing? I'm a newbie to ios. Please help.

1
  • 1
    Please paste more code... Commented Oct 10, 2014 at 18:53

2 Answers 2

56

This is a bug in the library. The header file (UIView+Toast.h) uses UIView but doesn't import <UIKit/UIKit.h>, so copying its source files into your project can give you this error.

(UPDATE: This bug was fixed on October 14, 2014.)

One way to fix this is to add #import <UIKit/UIKit.h> to the top of UIView+Toast.h.

Another way is to add #import <UIKit/UIKit.h> to your target's .pch file in the “Supporting Files” group, if your project has a .pch file. It looks like Xcode 6's project templates don't include a .pch file, so you might not be able to use this fix easily.

Sign up to request clarification or add additional context in comments.

3 Comments

Right Answer, i have just added #import <UIKit/UIKit.h> in .pch file. everything work fine.
Two thumbs up! I have a hybrid class where the swift class is trying to get an Objective class through a bridge header. I get this error and thousands more (for as many UIView as I declared i.e UILabel, UITextView etc). Surely enough the objective C class didn't import UIKit. Adding that fixed it. The question is: the Objective C class worked fine without importing that UIkit package; why?
Perhaps the project has a .pch (precompiled header) that imports UIKit.
2

Be sure to include UIKit, which is where UIView is defined: #import <UIKit/UIKit.h>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.