我使用object-c在协议中使用swift调用一个方法,但是它无法工作。
@objc
class ClientContext: NSObject, DataContextFacade {
func checkfetchFeedsWithNoSession()->NormalFeedViewModel?{
return NormalFeedViewModel()
}
}
和
#import <UIKit/UIKit.h>
@class ClientContext;
@class DataContextFacade;
@interface BusinessFeedsCollectionViewController : UICollectionViewController
@end
控制器:
#import "Koalac_DS-Swift.h"
@implementation BusinessFeedsCollectionViewController{
CKCollectionViewDataSource *_dataSource;
CKComponentFlexibleSizeRangeProvider *_sizeRangeProvider;
}
- (void)viewDidLoad {
[super viewDidLoad];
ClientContext *facade = [self getContextFacade];
[facade fetchFeedsWithNoSession];
}
实现:
SWIFT_PROTOCOL("_TtP9Koalac_DS17DataContextFacade_")
@protocol DataContextFacade
- (NormalFeedViewModel * __nullable)checkfetchFeedsWithNoSession;
- (void)fetchFeedsWithNoSession:(NSInteger)page perpage:(NSInteger)perpage longitude:(NSInteger)longitude latitude:(NSInteger)latitude;
- (void)fetchFeedsWithSession:(NSInteger)page perpage:(NSInteger)perpage;
- (void)fetchStoreCategory;
- (BOOL)uploadImageFile:(UIImage * __nonnull)image width:(NSInteger)width height:(NSInteger)height;
- (BOOL)isUserLogin;
@end
SWIFT_CLASS("_TtC9Koalac_DS13ClientContext")
@interface ClientContext : NSObject <DataContextFacade>
+ (ClientContext * __nonnull)shared;
- (void)fecthTest;
- (void)actionTest;
- (BOOL)isUserLogin;
- (void)userLogin:(NSString * __nonnull)userName password:(NSString * __nonnull)password deviceID:(NSString * __nonnull)deviceID;
- (NormalFeedViewModel * __nullable)checkfetchFeedsWithNoSession;
- (void)fetchFeedsWithNoSession:(NSInteger)page perpage:(NSInteger)perpage longitude:(NSInteger)longitude latitude:(NSInteger)latitude;
- (void)fetchFeedsWithSession:(NSInteger)page perpage:(NSInteger)perpage;
- (void)fetchStoreCategory;
- (BOOL)uploadImageFile:(UIImage * __nonnull)image width:(NSInteger)width height:(NSInteger)height;
- (void)isUserExist:(NSString * __nonnull)userName;
- (void)clearAllData:(void (^ __nonnull)(void))block;
- (void)deleteDataStore;
@end
我隐藏了一些细节。 [facade fetchFeedsWithNoSession];我打开“Koalac_DS-Swift.h”文件,找到:
{{1}}
但代码“[facade fetchFeedsWithNoSession]”不编译,如果我使用代码“[(ClientContext *)facade fetchFeedsWithNoSession]”,它通过编译,对象-c不能支持swift协议吗?有人知道为什么吗?