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
symfony/aiとlaravel/boost
77web
0
130
Generative UI & AI-Assistants for Your Angular Solutions
manfredsteyer
PRO
1
190
Foundation Models frameworkで画像分析
ryodeveloper
1
120
AI がコードを書く時代における新卒エンジニアの仕事風景 (2026) / New Graduate Engineers in the Era of AI Coding (2026)
sushichan044
0
220
初めてのKubernetes 本番運用でハマった話
oku053
0
130
ソフトウェア設計に溶けるインフラ ― AWS CDK のインフラ認識論
konokenj
2
550
ITヒヤリハットを整理してみた ~ライフサイクルと原因から考える再発防止策~
koukimiura
1
110
これからAgentCoreを触る方へトレンドはGatewayです
har1101
6
500
使用 Meilisearch 建立新聞搜尋工具
johnroyer
0
150
Apache Hive: Toward a Cloud Native Lakehouse
okumin
0
130
吝嗇家のためのAI活用 / AI development for miser - ChatGPT + Issue Driven Development
tooppoo
0
190
技術記事、 専門家としてのプログラマ、 言語化
mizchi
14
7.5k
Featured
See All Featured
Deep Space Network (abreviated)
tonyrice
0
230
GraphQLとの向き合い方2022年版
quramy
50
15k
Product Roadmaps are Hard
iamctodd
55
12k
The Cost Of JavaScript in 2023
addyosmani
55
10k
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
190
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
370
The Spectacular Lies of Maps
axbom
PRO
1
860
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
The World Runs on Bad Software
bkeepers
PRO
72
12k
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
190
Crafting Experiences
bethany
1
220
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
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