3

次の宣言を含むこのクラスに属するオブジェクトがあります。

ヘッダ

@interface MyClassObject : NSObject <NSCopying, NSPasteboardWriting, NSPasteboardReading>

@property (nonatomic, strong) NSArray *children;
@property (nonatomic, assign) NSInteger type;
@property (nonatomic, strong) NSString *name;
@property (nonatomic, strong) id node;

childrenは、このクラスの他のオブジェクトを保持し、またはのnodeオブジェクトを保持します。NSViewNSImageView

このタイプのオブジェクトを との間でコピー アンド ペーストできるようにしたいと考えていますNSPasteboard

私は周りにグーグルを持っていますが、説明はあいまいです。

このクラスを NSPasteboard にコピー可能/読み取り可能にする、つまりプロトコルに準拠させるにはどうすればよいNSPasteboardWritingですNSPasteboardReadingか?

私はこれがどのように行われるかについて少しも手がかりがありません.いつものように、Appleのドキュメントと同じものは何もありません.

4

2 に答える 2

0

書くことだけを議論します。それは基本的に読むのと同じです(もちろん逆です;))

書きます

  1. 書く型を宣言する

    - (NSArray *)writableTypesForPasteboard:(NSPasteboard *)pasteboard {
        return @[@"com.mycompany.mytype"];
    }
    
  2. データを書きます

    - (id)pasteboardPropertyListForType:(NSString *)type {
        //check the type we are asked to write
        if(![type isEqualToString:@"com.mycompany.mytype"]) return nil;    
    
        //create a _plist_ object
        // :: ONLY PLIST TYPES
        NSMutableDictionary *plist = [[NSMutableDictionary alloc] init];
    
        ...
    
        return plist;
    }
    
于 2015-02-22T10:19:42.180 に答える