gpt4 book ai didi

ios - 代表iOS

转载 作者:行者123 更新时间:2023-11-28 18:21:15 25 4
gpt4 key购买 nike

我正在尝试了解为什么无法从协议(protocol)中读取类型。我想这是因为@interface 在协议(protocol)之下,但如果有人能帮我找出问题并向我解释为什么那会很棒。

#import <UIKit/UIKit.h>

@protocol ARCHCounterWidgetDelegate <NSObject>

- (UIColor *) counterWidget: (ARCHCounterWidget *) counterWidget;

@end

@interface ARCHCounterWidget : UIView

@property (weak, nonatomic) id<ARCHCounterWidgetDelegate> delegate;

@end

最佳答案

您必须 forward declare类或协议(protocol):

// tell the compiler, that this class exists and is declared later:
@class ARCHCounterWidget;

// use it in this protocol
@protocol ARCHCounterWidgetDelegate <NSObject>
- (UIColor *) counterWidget: (ARCHCounterWidget *) counterWidget;
@end

// finally declare it
@interface ARCHCounterWidget : UIView
@property (weak, nonatomic) id<ARCHCounterWidgetDelegate> delegate;
@end

或:

// tell the compiler, that this protocol exists and is declared later
@protocol ARCHCounterWidgetDelegate;

// now you can use it in your class interface
@interface ARCHCounterWidget : UIView
@property (weak, nonatomic) id<ARCHCounterWidgetDelegate> delegate;
@end

// and declare it here
@protocol ARCHCounterWidgetDelegate <NSObject>
- (UIColor *) counterWidget: (ARCHCounterWidget *) counterWidget;
@end

关于ios - 代表iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20293784/

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