intention of this line return (err = 0); might well be return (err == 0);
A clue, previously assigned value is not used err = PasteboardPutItemFlavor (pb, (PasteboardItemID)1, kUTTypeUTF16PlainText, data, 0);
These are useful Xcode warnings that we should not ignore.
Nicolas