创建一个实现NSItemProviderWriting的类

它给出警告为:

1.类'DraggableEvent'不符合协议'NSItemProviderWriting'
2.Class属性'writableTypeIdentifiersForItemProvider'要求定义方法'writableTypeIdentifiersForItemProvider'-使用@dynamic或在此类实现中提供方法实现

代码:DraggableEvent.h

#import <Foundation/Foundation.h>

@interface DraggableEvent : NSObject <NSItemProviderWriting>
{

}

DraggableEvent.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/

10-10 22:22