NSPasteBoard的使用

取内容

NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
    NSArray *types = [pasteboard types];
    if ([types containsObject:NSPasteboardTypeString]) {
        NSString *s = [pasteboard stringForType:NSPasteboardTypeString];
        //do something...
    }

放内容

NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
[pasteboard clearContents];  //必须清空,否则setString会失败。
[pasteboard setString:@"Hello World!" forType:NSStringPboardType];

你可能感兴趣的:(NSPasteBoard的使用)