我可以防止将 Swift header 的扩展导出到 Objective-C 吗?
Can I prevent extensions from being exported to Swift header for Objective-C?
我有一个 Objective-C 项目,其中有 1 Swift class。 class 使用的框架也是用 Swift 编写的。 (使用 CocoaPods 来包含框架)
我的问题是 -Swift.h 文件导出的扩展符合框架中的协议。现在,当我尝试在 Objective-C 中导入 -Swift.h 文件时,它会抱怨找不到协议定义。
我不想导出这些扩展。它们仅用于此 class。我不能将 private 或 fileprivate 用于声明协议一致性的扩展。我还尝试在扩展声明之前添加 @nonobjc(将警告级联到我的方法中)并且它仍然被导出。
这是我的扩展:
extension MessagingExperience: MessagingDelegate {
...
}
extension MessagingExperience: MessagingNotificationDelegate {
...
}
并生成header:
@interface MessagingExperience (SWIFT_EXTENSION(Reference_App)) <MessagingDelegate>
- (void)MessagingObseleteVersion:(NSError * _Nonnull)error;
- (void)MessagingError:(NSError * _Nonnull)error;
@end
@interface MessagingExperience (SWIFT_EXTENSION(Reference_App)) <MessagingNotificationDelegate>
- (BOOL)shouldShowMessagingNotificationWithNotification:(MessagingNotification * _Nonnull)notification SWIFT_WARN_UNUSED_RESULT;
- (void)messagingNotificationTapped:(MessagingNotification * _Nonnull)notification;
- (UIView * _Nonnull)customMessagingNotificationViewWithNotification:(MessagingNotification * _Nonnull)notification SWIFT_WARN_UNUSED_RESULT;
@end
在 Objective-C class:
中包含 -Swift.h 产生的错误
找不到 'MessagingDelegate'
的协议声明
找不到 'MessagingNotificationDelegate'
的协议声明
有没有办法防止它出现在 header 中?
谢谢。
在MessagingExperience.swift中创建一个符合框架中定义的协议的私有class。因为是私有的class,生成的-Swift.h.
中不会指定协议
我有一个 Objective-C 项目,其中有 1 Swift class。 class 使用的框架也是用 Swift 编写的。 (使用 CocoaPods 来包含框架)
我的问题是 -Swift.h 文件导出的扩展符合框架中的协议。现在,当我尝试在 Objective-C 中导入 -Swift.h 文件时,它会抱怨找不到协议定义。
我不想导出这些扩展。它们仅用于此 class。我不能将 private 或 fileprivate 用于声明协议一致性的扩展。我还尝试在扩展声明之前添加 @nonobjc(将警告级联到我的方法中)并且它仍然被导出。
这是我的扩展:
extension MessagingExperience: MessagingDelegate {
...
}
extension MessagingExperience: MessagingNotificationDelegate {
...
}
并生成header:
@interface MessagingExperience (SWIFT_EXTENSION(Reference_App)) <MessagingDelegate>
- (void)MessagingObseleteVersion:(NSError * _Nonnull)error;
- (void)MessagingError:(NSError * _Nonnull)error;
@end
@interface MessagingExperience (SWIFT_EXTENSION(Reference_App)) <MessagingNotificationDelegate>
- (BOOL)shouldShowMessagingNotificationWithNotification:(MessagingNotification * _Nonnull)notification SWIFT_WARN_UNUSED_RESULT;
- (void)messagingNotificationTapped:(MessagingNotification * _Nonnull)notification;
- (UIView * _Nonnull)customMessagingNotificationViewWithNotification:(MessagingNotification * _Nonnull)notification SWIFT_WARN_UNUSED_RESULT;
@end
在 Objective-C class:
中包含 -Swift.h 产生的错误找不到 'MessagingDelegate'
的协议声明找不到 'MessagingNotificationDelegate'
的协议声明有没有办法防止它出现在 header 中?
谢谢。
在MessagingExperience.swift中创建一个符合框架中定义的协议的私有class。因为是私有的class,生成的-Swift.h.
中不会指定协议