gpt4 book ai didi

ios - swift 采用的 objective-c 协议(protocol)

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:01:49 26 4
gpt4 key购买 nike

这是放置在我使用的框架中的 objective c 协议(protocol)

@protocol AWSDKDelegate <NSObject>

/*
* @abstract AWSDKDelegate initialization lifecycle notifications to inform your app of success or failure
in SDK initialization and profile retrieval.
*/
- (void)initialCheckDoneWithError:(NSError*) error;
- (void)receivedProfiles:(NSArray*)profiles;

/*
* @abstract AWSDKDelegate Action Notifications used to inform your app to take various action
* @discussion stopNetworkActivity and resumeNetworkActivity are not supported on iOS 9
*/
- (void)wipe;
- (void)lock;
- (void)unlock;
- (void)stopNetworkActivity;
- (void)resumeNetworkActivity;
@end

创建桥头后,我试图在我用 Swift 编写的应用程序中采用它

//MARK: AWSDKDelegate Methods

func initialCheckDoneWithError(error: NSError!) {}
func receivedProfiles(profiles: NSArray!) {}
func unlock() {}
func wipe() {}
func stopNetworkActivity() {}
func resumeNetworkActivity() {}

但仍然报错:

Type 'AppDelegate' does not conform to protocol 'AWSDKDelegate'

最佳答案

1) 忘记实现lock方法2) 我不知道为什么,但事实证明使用 NSArray 的合适方式是 [AnyObject]。所以 func receivedProfiles(profiles: [AnyObject]!) 而不是 func receivedProfiles(profiles: NSArray!)

无论如何,我想知道为什么 XCode 没有对这些类型的错误进行更详细的描述。

关于ios - swift 采用的 objective-c 协议(protocol),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36113752/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com