Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Go言語からCocoaを使ってみた
Search
matuyuji
August 09, 2014
Programming
140
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Go言語からCocoaを使ってみた
matuyuji
August 09, 2014
More Decks by matuyuji
See All by matuyuji
Emacs × Touch Bar
matuyuji
2
1.9k
ARKit + SceneKitでMinesweeperを作ってみた
matuyuji
1
840
Go + QtでiOS アプリ開発
matuyuji
0
430
@_specialized なお話し
matuyuji
0
520
Xcode Souce Code Extensionを使ってみた
matuyuji
0
460
Codebeatを 試してみた
matuyuji
0
840
React Nativeで UIコンポーネントをつくる
matuyuji
0
1.1k
React Nativeを使ってみた
matuyuji
0
1.4k
SwiftでLens
matuyuji
1
1.1k
Other Decks in Programming
See All in Programming
AI × TiDD / 2026.09.05 Redmine 大阪
tokudiro
1
120
FastAPI の並行処理モデルを完全に理解する
hoto17296
9
3.9k
初心者DevRelとして参加者だった私が、DevRel Talks!#2に登壇するまでにしてきたこと
sokohirai
0
360
{ Android | Kotlin } Gradle Plugin in 2026
ryunen344
1
300
コンパウンドプロダクト開発のためのローカルプロセスマネージャー再発明 #layerxgo
izumin5210
0
660
デプロイ直後のレイテンシスパイクを調べたら、 Railsの仕様にたどり着いた
nhsykym
0
110
kubernetes コンポーネント開発入門 / 新卒N年目の勉強会&交流会!〜〇〇への誘い〜 #n_study
mazrean
0
190
XP祭りでしか伝わらないフリップネタ #xpjug
murabayashi
0
120
フロントエンドUIフレームワークのこれまでとこれから
ssssota
4
2k
スマート反転とウェブアクセシビリティ
camiha
0
180
【高い買い物LT会】初任給で話題の国産フィジカルAIを買った話
akagami
PRO
0
130
週末にAI-DLCを本気で回したら$1,600溶けた
hbashimizu
0
130
Featured
See All Featured
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
123
22k
Information Architects: The Missing Link in Design Systems
soysaucechin
1
1.1k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
1k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.4k
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
11k
Marketing to machines
jonoalderson
1
5.8k
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
540
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.6k
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
590
The untapped power of vector embeddings
frankvandijk
2
1.9k
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
600
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
230
23k
Transcript
(Pݴޠ͔Β$PDPB ΛͬͯΈͨ @matuyuji ! Cocoaษڧձؔ 2014.8.9
!NBUVZVKJ w TBGYEFWCMPHTQPUKQ w &NBDT͍ w 3FBDUJWF$PDPBؔ
(P͔Β$PDPBΛ͍͍ͨ
! func main() { app := cocoa.NSApplication_sharedApplication() win := cocoa.NSWindow_initWithContentRectStyleMaskBackingDefer(
cocoa.NSRect{0,0, 200,200}, NSTitledWindowMask, NSBackingStoreBuffered, false) win.CascadeTopLeftFromPoint(cocoa.NSPoint{20,20}) win.SetTitle(cocoa.NSString_initWithUTF8String("SomeApp")) win.MakeKeyAndOrderFront(nil) app.ActivateIgnoringOtherApps(true) ! fmt.Println(app, win) fmt.Println(app.GetClassName(), win.GetClassName()) ! app.Run(); } ͜ͷίʔυ͕ಈ͘Α͏ʹ͍ͨ͠ʂ
(P͔Β0CKFDUJWF$ ΛݺͿํ๏
$HP
$HP w (P͔Β$ݴޠίʔυΛݺͼग़͢Έ w ΘΓͱ͍ͮΒ͍
1BDLBHFz$z ! package main ! // #include <stdio.h> import "C"
! func main() { C.puts(C.CString("hello, world!")) } લͷίϝϯτ͕ ύοέʔδCͷͨΊͷ ίʔυʹͳΔ (Pจࣈྻˠ$จࣈྻ $ݴޠͷTUEJPIͷؔ
1BDLBHF$ )FMQFSGVODUJPO • func C.CString(string) *C.char (Pจࣈྻˠ$จࣈྻ • func C.GoString(*C.char)
string $จࣈྻˠ(Pจࣈྻ • func C.GoBytes(unsafe.Pointer, C.int) []byte $όΠτྻˠ(PόΠτྻ
! package main ! /* #include <stdio.h> ! char* hello()
{ return "hello, world!"; } */ import "C" ! func main() { C.puts(C.hello()) }
! package main ! /* int add(int x, int y)
{ return x + y; } */ import "C" import "fmt" ! func main() { fmt.Println(C.add(2, 3)) }
HPCVJMEYGPPHP foo.go foo.cgo1.go foo.cgo2.c Object Object Object cgo Binary 6l
6g clang pack _cgo_defun.c Object 6c ࣮ࡍͬͱෳࡶ‥
(PDPNNBOET 6a 8a 5a 6c 8c 5c 6g 8g 5g
6l 8l 5l assembler c compiler go compiler linker 6 (x86-64) 8 (x86-32) 5 (ARM) Plan 9 ༝དྷ ΞʔΩςΫνϟ πʔϧ
HPCVJMEYGPPHP foo.go foo.cgo1.go foo.cgo2.c Object Object Object cgo Binary 6l
6g clang pack _cgo_defun.c Object 6c
! void _cgo_2434c0b5a67e_Cfunc_add(void *v) { struct { int p0; int
p1; int r; char __pad12[4]; } __attribute__((__packed__)) *a = v; a->r = add(a->p0, a->p1); } ! int add(int x, int y) { return x + y; } ! void ɾ_Cfunc_add(struct{void *y[2];}p) { runtimeɾcgocall(_cgo_2434c0b5a67e_Cfunc_add, &p); } foo.cgo2.c _cgo_defun.c
HPCVJMEYGPPHP foo.go foo.cgo1.go foo.cgo2.c Object Object Object cgo Binary 6l
6g clang pack _cgo_defun.c Object 6c
! package main /* #cgo CFLAGS: -x objective-c #cgo LDFLAGS:
-framework Foundation #import <Cocoa/Cocoa.h> ! NSString* NSString_initWithUTF8String(char* text) { return [[NSString alloc] initWithUTF8String:text]; } ! const char* NSString_descripton(NSString* obj) { return [[obj description] UTF8String]; } */ import "C" import "fmt" ! func main() { str := C.NSString_initWithUTF8String(C.CString("foobar")) fmt.Println(C.GoString(C.NSString_descripton(str))) }
! package main /* #cgo CFLAGS: -x objective-c #cgo LDFLAGS:
-framework Cocoa #import <Cocoa/Cocoa.h> int StartApp(void) { [NSAutoreleasePool new]; [NSApplication sharedApplication]; [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular]; id menubar = [[NSMenu new] autorelease]; id appMenuItem = [[NSMenuItem new] autorelease]; [menubar addItem:appMenuItem]; [NSApp setMainMenu:menubar]; id appMenu = [[NSMenu new] autorelease]; id appName = [[NSProcessInfo processInfo] processName]; id quitTitle = [@"Quit " stringByAppendingString:appName]; id quitMenuItem = [[[NSMenuItem alloc] initWithTitle:quitTitle action:@selector(terminate:) keyEquivalent:@“q"] autorelease]; [appMenu addItem:quitMenuItem]; [appMenuItem setSubmenu:appMenu]; id window = [[[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 200, 200) styleMask:NSTitledWindowMask backing:NSBackingStoreBuffered defer:NO] autorelease]; [window cascadeTopLeftFromPoint:NSMakePoint(20,20)]; [window setTitle:appName]; [window makeKeyAndOrderFront:nil]; [NSApp activateIgnoringOtherApps:YES]; [NSApp run]; return 0; } */ import "C" ! func main() { C.StartApp() } LBWVFYBNQMFHP ˒
! func main() { app := cocoa.NSApplication_sharedApplication() win := cocoa.NSWindow_initWithContentRectStyleMaskBackingDefer(
cocoa.NSRect{0,0, 200,200}, NSTitledWindowMask, NSBackingStoreBuffered, false) win.CascadeTopLeftFromPoint(cocoa.NSPoint{20,20}) win.SetTitle(cocoa.NSString_initWithUTF8String("SomeApp")) win.MakeKeyAndOrderFront(nil) app.ActivateIgnoringOtherApps(true) ! fmt.Println(app, win) fmt.Println(app.GetClassName(), win.GetClassName()) ! app.Run(); }
TBGYDMBOHPCKDHP w $MBOH1ZUIPO#JOEJOHTΛར༻ w 0CKFDUJWF$ͷϔομ͔Β(PίʔυΛੜ python scripts/clang-objcgo.py import.h \ >
src/cocoa/import.go go build main ./main
$MBOH1ZUIPO#JOEJOHT w ιʔείʔυ͔Βநߏจ "45 Λੜ ! w 1ZUIPO͔Β؆୯ʹ͍͡ΕΔ w 4BGY$MBOHͷ1ZUIPOόΠϯσΟϯάͰ0CKFDUJWF$ͷ
ιʔείʔυΛύʔεͯ͠ΈΔ TBGYEFWCMPHTQPUKQ DMBOHQZUIPOPCKFDUJWFDIUNM python cindex-dump.py sample.h -c -m64 -ObjC DOMπϦʔΈ͍ͨͳͷ
translation_unit objc_interface_decl objc_property_decl objc_class_ref objc_instance_method_decl objc_instance_method_decl parm_decl objc_instance_method_decl parm_decl objc_class_ref
parm_decl sample.h foo hoge NSArray hoge setHoge: hoge barWithArray:limit: array NSArray limit @class NSArray; ! @interface Foo @property NSArray* hoge; - (int)barWithArray:(NSArray*)array limit:(int)limit; @end
ؔ࿈ϓϩδΣΫτ NLSBVU[PCKD ˒ PCKD@NTH4FOEͰ0CKFDUJWF$Λ͑ΔΑ͏ʹ͢Δ(PϥΠϒϥϦ NLSBVU[WBSJBEJD ˒
$ͷՄมҾͷؔΛݺΔΑ͏ʹͳΔ(PϥΠϒϥϦ 3JQ3JQDMBOH@DPNQMFUF ˒ WJNͷิϓϥάΠϯ DMBOHQZUIPOόΠϯσΟϯάར༻ TIJMHBQJSB0CK$SVTU ˒ 3VTUͰJ04ͷϥΠϒϥϦΛ࡞Δαϯϓϧ