gpt4 book ai didi

ios - 类不符合 NSItemProviderWriting 协议(protocol) - Objective-C

转载 作者:行者123 更新时间:2023-12-01 19:51:11 67 4
gpt4 key购买 nike

创建了一个实现 NSItemProviderWriting 的类

它给出警告为:

1.Class 'DraggableEvent' does not conform to protocol 'NSItemProviderWriting'
2.Class property 'writableTypeIdentifiersForItemProvider' requires method 'writableTypeIdentifiersForItemProvider' to be defined - use @dynamic or provide a method implementation in this class implementation



代码:DraggableEvent.h
#import <Foundation/Foundation.h>

@interface DraggableEvent : NSObject <NSItemProviderWriting>
{

}

可拖动事件.m
@implementation DraggableEvent
@synthesize writableTypeIdentifiersForItemProvider;

-(void)setWritableTypeIdentifiersForItemProvider:
(NSArray*)writableTypeIdentifiersForItemProvider{

}
-(NSArray*)writableTypeIdentifiersForItemProvider{
writableTypeIdentifiersForItemProvider = [[NSArray
alloc]initWithObjects:@"com.apple.ical.ics", nil];
return writableTypeIdentifiersForItemProvider;
}


- (nullable NSProgress *)loadDataWithTypeIdentifier:(NSString
*)typeIdentifier
forItemProviderCompletionHandler:(void (^)(NSData *
_Nullable data, NSError * _Nullable error))completionHandler{
completionHandler([self createVEvent], nil);
return nil;
}

最佳答案

我想通了。

请注意,该属性是类属性。
@property (class, NS_NONATOMIC_IOSONLY, readonly, copy) NSArray<NSString *> *readableTypeIdentifiersForItemProvider;

所以我们应该使用
+ (NSArray<NSString *> *)writableTypeIdentifiersForItemProvider;
+ (NSArray<NSString *> *)readableTypeIdentifiersForItemProvider;

代替 -

看下面这个问题

How to implement @property(class, readonly, copy, nonatomic) NSArray<NSString *> * _Nullable readableTypeIdentifiersForItemProvider;

关于ios - 类不符合 NSItemProviderWriting 协议(protocol) - Objective-C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45834960/

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