-
-
Notifications
You must be signed in to change notification settings - Fork 163
How to pull enum constants
Jonas Faber edited this page Apr 13, 2021
·
1 revision
we currently can not access global values easily so we sometimes need to fetch the values for those to convert them to go
How we would do it in objc
#import <Foundation/Foundation.h>
#import <AppKit/NSPasteboard.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
NSLog(@"NSPasteboardTypeURL:%@", NSPasteboardTypeURL);
NSLog(@"NSPasteboardTypeColor:%@", NSPasteboardTypeColor);
NSLog(@"NSPasteboardTypeFileURL:%@", NSPasteboardTypeFileURL);
NSLog(@"NSPasteboardTypeFont:%@", NSPasteboardTypeFont);
NSLog(@"NSPasteboardTypeHTML:%@", NSPasteboardTypeHTML);
NSLog(@"NSPasteboardTypeMultipleTextSelection:%@", NSPasteboardTypeMultipleTextSelection);
NSLog(@"NSPasteboardTypePDF:%@", NSPasteboardTypePDF);
NSLog(@"NSPasteboardTypePNG:%@", NSPasteboardTypePNG);
NSLog(@"NSPasteboardTypeRTF:%@", NSPasteboardTypeRTF);
NSLog(@"NSPasteboardTypeRTFD:%@", NSPasteboardTypeRTFD);
NSLog(@"NSPasteboardTypeRuler:%@", NSPasteboardTypeRuler);
NSLog(@"NSPasteboardTypeSound:%@", NSPasteboardTypeSound);
NSLog(@"NSPasteboardTypeString:%@", NSPasteboardTypeString);
NSLog(@"NSPasteboardTypeTabularText:%@", NSPasteboardTypeTabularText);
NSLog(@"NSPasteboardTypeTextFinderOptions:%@", NSPasteboardTypeTextFinderOptions);
NSLog(@"NSPasteboardTypeTIFF:%@", NSPasteboardTypeTIFF);
}
return 0;
}
How we can do it using EmbeddingObjectiveC
package main
/*
#cgo CFLAGS: -x objective-c
#cgo LDFLAGS: -lobjc -framework Cocoa
#include <Cocoa/Cocoa.h>
void Main() {
NSLog(@"NSPasteboardTypeURL:%@", NSPasteboardTypeURL);
NSLog(@"NSPasteboardTypeColor:%@", NSPasteboardTypeColor);
NSLog(@"NSPasteboardTypeFileURL:%@", NSPasteboardTypeFileURL);
NSLog(@"NSPasteboardTypeFont:%@", NSPasteboardTypeFont);
NSLog(@"NSPasteboardTypeHTML:%@", NSPasteboardTypeHTML);
NSLog(@"NSPasteboardTypeMultipleTextSelection:%@", NSPasteboardTypeMultipleTextSelection);
NSLog(@"NSPasteboardTypePDF:%@", NSPasteboardTypePDF);
NSLog(@"NSPasteboardTypePNG:%@", NSPasteboardTypePNG);
NSLog(@"NSPasteboardTypeRTF:%@", NSPasteboardTypeRTF);
NSLog(@"NSPasteboardTypeRTFD:%@", NSPasteboardTypeRTFD);
NSLog(@"NSPasteboardTypeRuler:%@", NSPasteboardTypeRuler);
NSLog(@"NSPasteboardTypeSound:%@", NSPasteboardTypeSound);
NSLog(@"NSPasteboardTypeString:%@", NSPasteboardTypeString);
NSLog(@"NSPasteboardTypeTabularText:%@", NSPasteboardTypeTabularText);
NSLog(@"NSPasteboardTypeTextFinderOptions:%@", NSPasteboardTypeTextFinderOptions);
NSLog(@"NSPasteboardTypeTIFF:%@", NSPasteboardTypeTIFF);
}
*/
import "C"
func main() {
C.Main()
}