How to convert to id with conforming protocol?

67 views Asked by At

Why is following code failed?

NSPasteboardItem* pasteboard_item = [NSPasteboardItem new];
id<NSPasteboardWriting> temp_obj = pasteboard_item;

I am newbie in Objective-c, but as I understand, NSPasteboardItem conforms NSPasteboardWriting protocol and such assignment should be allowed.

Xcode says:

Cannot initialize a variable of type id with lvalue of type 'NSPasteboardItem*'

Note: NSPasteboardItem is the class from AppKit to work with NSPasteBoard

0

There are 0 answers