0

I'm working on an iOS project that was done few years back in Objective C. So I've to implement some new features to the existing one, so this time I'm using Swift for that purpose.

I've added a new Swift class:

class CampView: UIView
{
   // Code
}

I want to access this class in one of my existing Objective C class. So I did like:

@class CampView;
@interface NewCampViewController : UIViewController

@property (nonatomic, strong) IBOutletCollection(CampView) NSArray *campTypes;

@end

But when I connect it to my Storyboard, it is crashing with a message:

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key campTypes.'

Also I can't import my system generated Swift header file to this particular class, when I do that it throws an error like :

'MyApp-Swift.h' file not found

That's why I used @class CampView; in the above snippet. While investigating I found that my NewCampViewController.h is included in the Objective C bridging header. So suspect it is due to circular dependency, but I couldn't fix it yet.

Can anybody please help me to fix this issue ?

Midhun MP
  • 103,496
  • 31
  • 153
  • 200
  • 1
    The exception doesn't look like it is anything to do with a Swift dependency - it looks like a simple IBOutlet issue. Are you sure you have connected your storyboard to an IBOutletCollection and not an IBOutlet. – Paulw11 Jul 20 '15 at 07:36
  • @Paulw11: I connected to an IBOutletConnection. I'm sure. I tried several times by removing and adding again – Midhun MP Jul 20 '15 at 07:58

1 Answers1

8

1) Are you doing the import (import "MyApp-Swift.h") from the .m file of your Objective-C class? This should avoid a circular dependancy. If you are doing @class CampView, Xcode expects you will import CampView class in the .m file. @class is basically just a cast for your header file.

If you are getting the file not found error doing the -swift.h import, trying debugging by looking through this post. Also, I believe if you change the name of your project, the import name may not change along with it. Check the name of your module.

If you still believe it is possible that you are getting this file not found issue from a circular import, the easiest way to verify that is the case would be to add the import to another obj-c file you know will not have a circular call, and init a test instance of CampView.

2) If the problem is as @ Paulw11 suggests, the connection in IB, you can check if the connection is made by checking checking the round dot next to the property connected in code. Clicking on it should show what it is connected to. An empty dot is not connected. enter image description here For more information on how to properly make a connection from IB to a property in your code see this link.

Community
  • 1
  • 1
Rich Fox
  • 2,194
  • 18
  • 20
  • So I need to declare the property in .m file right ? – Midhun MP Jul 20 '15 at 07:59
  • you do not need to if you are using '@class CampView'. '@class' basically tells the header file, let me declare properties of class type CampView, but don't worry I am going to import it in the .m file. – Rich Fox Jul 20 '15 at 08:08
  • hey @Midhun MP did you ever figure this out? – Rich Fox Jul 22 '15 at 03:23
  • 1
    Yes, actually the issue is with Xcode, it is not recognizing my `NewCampViewController` in storyboard. I deleted the files, quit Xcode and added them again. It solved the issue :) Thanks for your answer – Midhun MP Jul 22 '15 at 06:03
  • @MidhunMP Could you either mark that this answer solved your question, or provide yours answer, just to notify people that the problem is solvable? :) – olha Jun 14 '19 at 19:20