1

I’m developing my with swift, Now few of my older files are written in objective-c. So I create bridge for class communication.

One of my delegate class is written in objective-c, Now I want to know which is the current class which invokes my delegate.

I’m trying with isKindOfCalss, its its fire an error like identifies is not found. Once I import swift file error changes to forward declaration.

Any suggestions what should I do for such need?

Also Import is not working in my case, Please see attached images.

enter image description here

enter image description here

enter image description here

Community
  • 1
  • 1
Ashwin Kanjariya
  • 1,019
  • 2
  • 10
  • 22
  • I'm using xcode 8.3, I have gone with few so question related import swift class in object file.... but non has helped me. ;( – Ashwin Kanjariya Apr 11 '17 at 11:50
  • isKindOfClass will be available for Swift classes if and only if they inherit from NSObject which does not happen by default. – Kamil.S Apr 11 '17 at 12:05
  • HomeVC class is a swift class ..? – Anil Kumar Apr 11 '17 at 12:33
  • Yes HomeVC is swift class, and using it as delegate for my objc class – Ashwin Kanjariya Apr 11 '17 at 12:40
  • Delegation is working fine but the error while checking kind of delegate class. – Ashwin Kanjariya Apr 11 '17 at 12:41
  • What are you trying to accomplish by identifying the type? Generally this sort of thing is done better through Protocols or similar, writing the implementation so that the type itself handles the special case rather than checking for the type and having to write custom code for each case. This leads to cleaner code and less chances to forget a special case, you write it once and then use it everywhere you need it. –  Apr 11 '17 at 12:59
  • @ColGraff You are right for my current scenario, as I'm doing nothing with class type, Just checking type to take some actions. Thank you all – Ashwin Kanjariya Apr 11 '17 at 13:04
  • Also, it would be best if you could post more of your code and as text, not images. That makes it easier to verify. You show an image of import statements which are commented-out. I assume you don’t have them commented-out in your actual code, right? Can you possibly put the project (or a working subset of it) up in a repository somewhere? –  Apr 11 '17 at 13:06
  • Yes, first two images was for error, and off course not, all codes were not in comment. I have sent image to explain what i had tried so far. – Ashwin Kanjariya Apr 11 '17 at 13:09
  • That seems like a circular dependency. – Sulthan Apr 11 '17 at 13:24
  • Just find cause, as my product name in project configuration is "CFBundleDisplayName" due to multi-language, and based on device language my app name is getting set. damn this sucks man. wasted almost 2 hours. I was checking here and there.... Any way thank you all for help – Ashwin Kanjariya Apr 11 '17 at 13:34

2 Answers2

0

Haven't met your problem before, but I can suggest you to just rewrite this code without isKindOfClass stuff. You can use some returned enum from base class and then check it instead

@objc enum EnumSubstitution: Int {
    // several options
}

protocol YourDelegateProtocol {
   // your methods
   var enumSubstitutionForIsKindOf: EnumSubstitution {get}
}

I didn't check the code, but, suppose, you've got the idea

EDITED:

I mean, you can use EnumSubstitution up next in your code, so instead of writing

if ([self.delegate isKindOfClass: [yourClass class]])

you just use

if (self.delegate.enumSubstitutionForIsKindOf == firstOption)

and so on

Vladyslav Zavalykhatko
  • 15,202
  • 8
  • 65
  • 100
0

From the looks of your answer your import statements are missing the capital S in Swift.

try changing

#import "HomeVC-swift.h" 

to

#import "HomeVC-Swift.h"
Luke Chase
  • 322
  • 1
  • 18