Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Potatotips#7: Box C String Tip
Search
Shin Yamamoto
May 15, 2014
Programming
2.8k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Potatotips#7: Box C String Tip
Shin Yamamoto
May 15, 2014
More Decks by Shin Yamamoto
See All by Shin Yamamoto
Meet CoreDevice and devicectl
scenee
0
630
DocCのドキュメントをGithub Pagesで公開する
scenee
2
720
SwiftライブラリのObjC対応における落とし穴と回避策
scenee
0
340
Testing a constraint-based layout of UIView
scenee
1
1.4k
Playing Sheet presentation style on iOS 13
scenee
0
700
Fluid Interfacesの実践
scenee
4
1.7k
Introducing Relax
scenee
0
630
Other Decks in Programming
See All in Programming
初めてのKubernetes 本番運用でハマった話
oku053
0
130
yield再入門 #phpcon
o0h
PRO
0
500
そのテスト、説明できますか?~LWテスト戦略FW~のご紹介
nakahara
0
210
吝嗇家のためのAI活用 / AI development for miser - ChatGPT + Issue Driven Development
tooppoo
0
190
ソフトウェア設計に溶けるインフラ ― AWS CDK のインフラ認識論
konokenj
2
550
SLOをサービス品質の共通言語にするために 取り組んできたこと
wakana0222
0
510
symfony/aiとlaravel/boost
77web
0
130
ランチタイムLT会3周年!ランチタイムLT会を3年間続けられたお話
y0hgi
1
140
ローカルLLMでどこまでコードが書けるか -拡張版 / How much code can be written on a local LLM Extended
kishida
12
4.8k
鹿野さんに聞く!『TypeScriptコードレシピ集』で磨く実践力
tonkotsuboy_com
4
1.1k
コーディングルールの鮮度を保ちたい for SRE NEXT 2026 / keep-fresh-go-internal-conventions-sre-next-2026
handlename
0
140
これからAgentCoreを触る方へトレンドはGatewayです
har1101
6
500
Featured
See All Featured
Git: the NoSQL Database
bkeepers
PRO
432
67k
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
2
4.1k
30 Presentation Tips
portentint
PRO
1
350
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
190
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
420
Faster Mobile Websites
deanohume
310
32k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
3
1.1k
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
360
Site-Speed That Sticks
csswizardry
13
1.3k
The Curious Case for Waylosing
cassininazir
1
430
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
1
390
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.4k
Transcript
Box C String Tip potatotips #7 @SCENEE / iOS
ࣗݾհ • @SCENEE : “Shin Yamamoto” • iOSΞϓϦέʔγϣϯ։ൃ • UIEvolution
K.K. (ຊࣾSeattle)
Box C String • @(<expression>)ͷBoxϦςϥϧͰɺchar* ɺconst char *͔ΒNSStringੜͰ͖· ͢ɻ •
※Τϯίʔυ͕UTF8Ͱɺ\0͕ऴͷจࣈྻΛ ఆ͍ͯ͠·͢
Use cases • libXMLͰɺύʔεͨ͠ΛNSStringม͢ Δͱ͖ • C༝དྷͷϥΠϒϥϦͷจࣈྻΛϩάग़ྗ͢Δͱ ͖
Use cases • libXMLͰɺύʔεͨ͠ΛNSStringม͢ Δͱ͖ • C༝དྷͷϥΠϒϥϦͷจࣈྻΛϩάग़ྗ͢Δͱ ͖ • One
More!!
Macroͷreplacement token ΛNSStringͰऔಘ͢Δ
↓ͷΑ͏ʹMacroͷΛ char*ͱͯ͠ औΓग़ͯ͠ɺNSStringͱͯ͠ѻ͑Δ #define __str(x) #x #define str(x) __str(x) #define
FOO foo ! ! { NSLog(@"%@", @(str(FOO))); ——> “foo” }
͜ΕΛԠ༻͢Δͱ͜ΜͳϞσ ϧίʔυ͕ॻ͚·͢
·ͣɺҎԼͷΑ͏ʹmacroͰɺ͋Δ ActionΛఆٛ͠·͢ɻ #pragma mark ########################### ! #define __str(x) #x #define
str(x) __str(x) ! #define Action1 saltAction #define Action2 garlicAction #define Action3 wasabiAction ! #pragma mark ###########################
࣍ʹɺ͜ΕΛར༻ͯ͠ɺUITableView༻ ͷϝχϡʔϞσϧΛ࡞Δͱ @interface PTMenu() @property NSArray *menuList; @end ! @implementation
PTMenu ! - (instancetype)init { self = [super init]; if (self) { self.menuList = @[@{TITLE : @"Salt", ACTION : @(str(Action1)":")}, // ACTION : [NSString stringWithUTF8String:str(Action1)":"]}, @{TITLE : @"Garlic", ACTION : @(str(Action2)":")}, @{TITLE : @"Wasabi", ACTION : @(str(Action3)":")}, ]; } return self; }
͜Μͳ෩ʹɺSELΛͬͯ ηϧબ࣌ͷϩδοΫΛॻ͚Δʂ #pragma mark - UITableView delegate - (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath: (NSIndexPath *)indexPath { NSString *action = self.menuList[indexPath.row][ACTION]; SEL selector = NSSelectorFromString(action); if ([self respondsToSelector:selector]) { [self performSelector:selector withObject:self];// NOTE: Waringɺ Actionͷϝιου͕ఆٛ͞Ε͍ͯΕͳ͍ɻ } } ! #pragma mark - Actions ! - (void)Action1:(id)sender { UIAlertView *av = [[UIAlertView alloc] init]; av.title = @(str(Action1)); [av addButtonWithTitle:@"OK"]; av.cancelButtonIndex = 0; [av show]; }
References • http://stackoverflow.com/questions/195975/ how-to-make-a-char-string-from-a-c-macros- value • http://gcc.gnu.org/onlinedocs/cpp/ Stringification.html#Stringification