Why doesn't the NSPasteboard -type return a union of the types contained in the NSPasteboardItem?

The documentation for NSPasteboard -typesreads:

Return value

An array of NSString objects containing a union of data types declared for the entire cardboard items on the receiver. The returned types are listed in the order in which they were declared.

Despite this, I NSPasteboardonly have one NSPasteboardItemand it [pboard types]returns more types than [item types]. Can anyone explain this?

The code

Here is the code that indicates the problem:

- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender {
    NSPasteboard *pboard = [sender draggingPasteboard];

    // Prove that there only one item
    if ([[pboard pasteboardItems] count] > 1)
        return NO;

    for (NSString* type in [pboard types])
        NSLog(@"Pasteboard type: %@", type);

    NSPasteboardItem* item = [[pboard pasteboardItems] objectAtIndex:0];

    for (NSString* type in [item types])
        NSLog(@"Item type: %@", type);

    return NO; // Ignore for example
}

Output

When I drag the link from Safari, I get the following output:

Pasteboard type: dyn.ah62d4rv4gu8zs3pcnzme2641rf4guzdmsv0gn64uqm10c6xenv61a3k
Pasteboard type: WebURLsWithTitlesPboardType
Pasteboard type: dyn.ah62d4rv4gu8yc6durvwwaznwmuuha2pxsvw0e55bsmwca7d3sbwu
Pasteboard type: Apple URL pasteboard type
Pasteboard type: public.url
Pasteboard type: CorePasteboardFlavorType 0x75726C20
Pasteboard type: public.url-name
Pasteboard type: CorePasteboardFlavorType 0x75726C6E
Pasteboard type: public.utf8-plain-text
Pasteboard type: NSStringPboardType
Item type: dyn.ah62d4rv4gu8zs3pcnzme2641rf4guzdmsv0gn64uqm10c6xenv61a3k
Item type: dyn.ah62d4rv4gu8yc6durvwwaznwmuuha2pxsvw0e55bsmwca7d3sbwu
Item type: public.url
Item type: public.url-name
Item type: public.utf8-plain-text

Wild speculation

, [item types] , [pboard types], UTI. [pboard types], -, UTI (?) , ...

, , , UTI , , WebURLsWithTitlesPboardType ( dyn.ah62d4rv4gu8zs3pcnzme2641rf4guzdmsv0gn64uqm10c6xenv61a3k), dyn.(...) UTI. , .

WebURLsWithTitlesPboardType - UTI? [pboard types] ...

+3
3

, NSPasteboard -types . :

NSString, , , , UTI.

OS X 10.6+, NSPasteboard -types NSPasteboardItem -types, UTI.

UTI UTI, UTTypeCreatePreferredIdentifierForTag(); , (kUTTagClassFilenameExtension, kUTTagClassMIMEType, kUTTagClassNSPboardType kUTTagClassOSType). . - ( CFStringRef). , NULL, UTI, -, kUTTypeData.

, () UTI "WebURLsWithTitlesPboardType":

CFStringRef webURLsWithTitlesUTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassNSPboardType, CFSTR("WebURLsWithTitlesPboardType"), kUTTypeData);
+4

UTTypeCreatePreferredIdentifierForTag(), , UTI, pboard. kUTTagClassNSPboardType tagClass, pboard - ( NULL). , , , UTI, non WebURLsWithTitlesPboardType. , , , .

+2

, Mac OS X, .

If you are developing for Mac OS X 10.6 or later only, you can completely ignore the method -typesand focus directly on the cardboard elements. If you are targeting Mac OS X 10.5 or earlier, you need to either use deprecated methods (including -types), or check for new methods and types before using them (through weak coupling and reasonable use NSClassFromString()and -respondsToSelector:.)

+1
source

Source: https://habr.com/ru/post/1754889/


All Articles