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
530
Xcode Souce Code Extensionを使ってみた
matuyuji
0
470
Codebeatを 試してみた
matuyuji
0
850
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
ハーネス設計入門 〜 基礎知識の整理から実務へのステップアップ 〜
kinopeee
28
33k
Workers Cache を知る
syumai
0
370
iOS 27でニュースアプリはどう変わる!? 〜日経電子版の新機能対応と、開発事例から〜
lynnswap
7
13k
Web Framework Benchmark Battle 2026, Any%
a_matsuda
2
2.5k
AmebaブログはKMPから卒業します
kmars0605
0
200
3回つくってわかった、 定期実行ジョブ基盤の本質情報
takai
0
510
[Rails World 2026] Durable orchestration on Rails: from continuation to workflow
palkan
1
750
S3 TablesのIcebergデータに、AIエージェントからアクセスしてみた / 20261016developersio2026joetsu-accessing-iceberg-in-s3tables-via-agent
kasacchiful
PRO
0
160
UPDATE をやめる — EF Core でマスタをバージョン管理する
panda728
PRO
0
1.2k
PumaからFalconに移行したRailsアプリケーションでの実践
falcon8823
0
180
dotNET_vulnclicker_intro.pdf
deka_morita
0
140
複雑なUIコンポーネントとの ⻑い付き合い⽅:波及するバグからテスト戦略を経て、安全な再設計へ
mixplace
0
430
Featured
See All Featured
Intergalactic Javascript Robots from Outer Space
tanoku
273
28k
A Tale of Four Properties
chriscoyier
163
24k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
20k
Reality Check: Gamification 10 Years Later
codingconduct
0
2.3k
Why Our Code Smells
bkeepers
PRO
340
58k
Producing Creativity
orderedlist
PRO
348
41k
Agile that works and the tools we love
rasmusluckow
331
22k
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
630
brightonSEO & MeasureFest 2025 - Winning Strategies for Black Friday CRO & PPC - Christian Goodrich
cargoodrich
3
870
Site-Speed That Sticks
csswizardry
13
1.6k
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.8k
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ͷϥΠϒϥϦΛ࡞Δαϯϓϧ