Reputation: 845
I've a very similar issue to this question, but I don't know how to fix it.
I have a swift bridging header file to expose ObjC classes to swift and a swift interface header (automatically generated by Xcode during compile time) to expose swift classes to ObjC.
I am using swift types in an ObjC file, say A.mm, so I've included the swift interface header in that file.
Recently, I extended my AppDelegate to conform to UNUserNotificationCenterDelegate to handle notifications.
import UIKit
import UserNotifications
extension AppDelegate: UNUserNotificationCenterDelegate {
....
}
But this suddenly causes a compilation error in A.mm - 'Cannot find protocol declaration for 'UNUserNotificationCenterDelegate'. In the swift interface header file, I can see that UNUserNotificationCenterDelegate is referenced, so just adding this line before importing the swift interface header will work.
#import <UserNotifications/UserNotifications.h>
But it makes no sense to do so - since the code in A.mm has nothing to do with UserNotifications. I had to include swift interface header file here because I need to use some swift types, but none of that is related to UserNotifications. So, I'm not comfortable in importing UserNotifications.h as it just causes confusion. I think the swift interface header should somehow include UserNotifications.h, since that's where the problem originates.
Following this answer, I ensured to include
import UserNotifications
in the AppDelegate file, as shown above... but it still fails to compile. So adding the swift include is not the solution.
What am I missing to ensure that the swift interface header file includes the UserNotifications.h file? Is there no way but to include UserNotifications.h before including the swift interface header in A.mm? (I don't like this).
Upvotes: 2
Views: 535