0

In the past I have created subclasses of NSObject and return various types from strings to UIColor's.

Here is an example piece of code:

enter image description here

However I recently started a new project in iOS 8 and have gone to do the same thing but I am getting the following error:

enter image description here

I am able to return NSString's, NSDictionary's, etc but am unable to return things that are UI based. So UIColor, UITabBar, etc.

The first project was created before updating to Xcode 6 and the second one (one with issue) was created after upgrading. Both are using Objective C.

I can't see any difference between the 2 files. Does anyone know why I might be experiencing this issue?

Many thanks.

pls
  • 1,522
  • 2
  • 21
  • 41

1 Answers1

4

Add on top

#import <UIKit/UIKit.h>

That's because UIColor is class from UIKit framework, so you need to import UIKit as well.

So why this error occurred from Xcode 6 ?
Because Apple has removed PCH default support, refer to my previous answer

Community
  • 1
  • 1
l0gg3r
  • 8,864
  • 3
  • 26
  • 46
  • Hi l0gg3r, thanks for the response. So does that mean we should handle creating helper classes differently? Or is it still best to subclass NSObject and then add the import if we need to return any UI elements? – pls Nov 28 '14 at 14:52
  • Hi, the best practice is to add `@class UIColor;` on top of the .h file, and `#import ` in .m file – l0gg3r Nov 28 '14 at 14:55
  • So they removed it to make apps compile longer so people switch to Swift? – pronebird Nov 28 '14 at 23:51