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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
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.3k
Playing Sheet presentation style on iOS 13
scenee
0
690
Fluid Interfacesの実践
scenee
4
1.7k
Introducing Relax
scenee
0
620
Other Decks in Programming
See All in Programming
そのテスト、説明できますか?~LWテスト戦略FW~のご紹介
nakahara
0
160
AI駆動開発を妨げる技術的負債の解消アプローチ / ai-refactoring-approach
minodriven
12
6.6k
Claspは野良GASの夢をみるか
takter00
0
210
はてなアカウント基盤 State of the Union
cockscomb
0
690
TypeScript+Orvalで実現する型安全かつ堅牢でスケーラブルなマルチチャネル通知基盤 / TSKaigi Night talks ~after conference~
d0riven
0
360
エンジニアと一緒にテストコードの設計と実装を改善した話
mototakatsu
0
220
スマートグラスで並列バイブコーディング
hyshu
0
260
dRuby over BLE
makicamel
2
390
鹿野さんに聞く!『TypeScriptコードレシピ集』で磨く実践力
tonkotsuboy_com
2
750
Language Server 使ってる? 〜VSCode と Zed の場合〜 / Are you using a Language Server? ~For VS Code and Zed~
handlename
0
800
「なぜそう決めたのか」を残し続ける仕組み ― Notion AI カスタムエージェント × Slack連携による設計判断の自動記録 - NIKKEI Tech Talk #47
niftycorp
PRO
0
230
A2UI という光を覗いてみる
satohjohn
1
150
Featured
See All Featured
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
150
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
2
1.5k
How to Talk to Developers About Accessibility
jct
2
250
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
370
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.2k
Rebuilding a faster, lazier Slack
samanthasiow
85
9.5k
Automating Front-end Workflow
addyosmani
1370
210k
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
430
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
200
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.6k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
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