NSPasteboard generalPasteboard returns nil

I am trying to copy NSString to a file cabinet from NSBundle , which is loading inside another program as a plugin.

For some reason, [NSPasteboard generalPasteboard] returns nil.

My Apple Code NSPasteboard Documentation and NSPasteboard Programming Guide :

 NSPasteboard *pasteboard = [NSPasteboard generalPasteboard]; // Outputs: (null) NSLog(@"%@", pasteboard); [pasteboard clearContents]; BOOL copiedToPasteboard = [pasteboard writeObjects:@[@"The string"]]; 

Is there something that I could inadvertently do to trigger this?

+4
source share
2 answers

My problem was resolved by reinstalling my OS.

I can only assume that something, somewhere, at some point, became corrupt, causing this abyss.

+1
source

I created a minimal application that downloads the package and adds the registration of the value returned by [NSPasteboard generalPasteboard] at each step. Unfortunately, I could not reproduce this problem. Here is the result I get:

 NUAppDelegate> init:<NSPasteboard: 0x100647740> NUAppDelegate> awakeFromNib:<NSPasteboard: 0x100647740> NUAppDelegate> applicationDidFinishLaunching::<NSPasteboard: 0x100647740> Loading plugin Plugin> init:<NSPasteboard: 0x100647740> Plugin> someMethod:<NSPasteboard: 0x100647740> 

Without details, I don’t see how we can find the answer. Do you have a code that we can download or verify?

+1
source

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


All Articles