Cocoa by cgo
Upcoming SlideShare
Loading in...5
×
 

Cocoa by cgo

on

  • 934 views

 

Statistics

Views

Total Views
934
Views on SlideShare
832
Embed Views
102

Actions

Likes
5
Downloads
6
Comments
0

2 Embeds 102

http://connpass.com 77
https://twitter.com 25

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Cocoa by cgo Cocoa by cgo Presentation Transcript

  • Cocoa by cgo Hajime Hoshi (星一)
  • About Myself • Hajime Hoshi (星一) • Software Engineer
  • What’s cgo? • The special library/tool to use C programs • // void HelloWorld() { // printf("Hello, World!n"); // } import "C" func main() { C.HelloWorld() } View slide
  • Theme • I wanna develop Mac OS X applications in Go! • The more Go, the more merrier • So, can cgo treat Objective-C? • YES!!!! View slide
  • package main   // #cgo CFLAGS: -x objective-c // #cgo LDFLAGS: -framework Cocoa // #import <Cocoa/Cocoa.h> // // void run() { // @autoreleasepool { // NSApplication* app = [NSApplication sharedApplication]; // NSWindow* window = [[NSWindow alloc] // initWithContentRect:NSMakeRect(0,0,200,200) // styleMask:NSTitledWindowMask // backing:NSBackingStoreBuffered // defer:NO]; // [window orderFrontRegardless]; // [app run]; // } // } // import "C"   func main() { C.run() }
  • package main   // #cgo CFLAGS: -x objective-c // #cgo LDFLAGS: -framework Cocoa // #import <Cocoa/Cocoa.h> // // void run() { // @autoreleasepool { // NSApplication* app = [NSApplication sharedApplication]; // NSWindow* window = [[NSWindow alloc] // initWithContentRect:NSMakeRect(0,0,200,200) // styleMask:NSTitledWindowMask // backing:NSBackingStoreBuffered // defer:NO]; // [window orderFrontRegardless]; // [app run]; // } // } // import "C"   func main() { C.run() } // #cgo CFLAGS: -x objective-c // #cgo LDFLAGS: -framework Cocoa
  • package main   // #cgo CFLAGS: -x objective-c // #cgo LDFLAGS: -framework Cocoa // #import <Cocoa/Cocoa.h> // // void run() { // @autoreleasepool { // NSApplication* app = [NSApplication sharedApplication]; // NSWindow* window = [[NSWindow alloc] // initWithContentRect:NSMakeRect(0,0,200,200) // styleMask:NSTitledWindowMask // backing:NSBackingStoreBuffered // defer:NO]; // [window orderFrontRegardless]; // [app run]; // } // } // import "C"   func main() { C.run() } // #import <Cocoa/Cocoa.h>
  • package main   // #cgo CFLAGS: -x objective-c // #cgo LDFLAGS: -framework Cocoa // #import <Cocoa/Cocoa.h> // // void run() { // @autoreleasepool { // NSApplication* app = [NSApplication sharedApplication]; // NSWindow* window = [[NSWindow alloc] // initWithContentRect:NSMakeRect(0,0,200,200) // styleMask:NSTitledWindowMask // backing:NSBackingStoreBuffered // defer:NO]; // [window orderFrontRegardless]; // [app run]; // } // } // import "C"   func main() { C.run() }
  • package main   // #cgo CFLAGS: -x objective-c // #cgo LDFLAGS: -framework Cocoa // #import <Cocoa/Cocoa.h> // // void run() { // @autoreleasepool { // NSApplication* app = [NSApplication sharedApplication]; // NSWindow* window = [[NSWindow alloc] // initWithContentRect:NSMakeRect(0,0,200,200) // styleMask:NSTitledWindowMask // backing:NSBackingStoreBuffered // defer:NO]; // [window orderFrontRegardless]; // [app run]; // } // } // import "C"   func main() { C.run() } import "C"   func main() { C.run() }
  • Demo
  • Appendix • As of Go 1.2? • Objective-C couldn’t be compiled in Go 1.1. • I’m not sure this is an official feature.
  • Appendix • Be careful for threads! • Calling Cocoa functions from not- appropriate goroutines might crash the application.
  • Appendix • Long compiling time! (because of Objective-C)
  • Appendix • Go command recognizes *.c files, but not *.m (or *.mm) files. • You need to write Objective-C program in C files (Issue 6536). Sigh...
  • Oshimai