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
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
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
LLM本来の能力を解き放つサンドボックス技術とAI民主化への適用
yukukotani
3
4.5k
1B+ /day規模のログを管理する技術
broadleaf
0
110
Contextとはなにか
chiroruxx
1
370
The NotImplementedError Problem in Ruby
koic
1
920
「AIで開発し、AIを届ける」をEvalでつなぐ 〜AIネイティブに始めるプロダクト開発の実践〜 / Connecting "Develop with AI, deliver AI" with Eval
rkaga
4
5.4k
Mujeres en SEO Summit 2026 - Greatest Disaster Hits en Web Performance
guaca
0
200
ふつうのFeature Flag実践入門
irof
8
4.2k
AIで効率化できた業務・日常
ochtum
0
140
TypeScript+Orvalで実現する型安全かつ堅牢でスケーラブルなマルチチャネル通知基盤 / TSKaigi Night talks ~after conference~
d0riven
0
360
鹿野さんに聞く!『TypeScriptコードレシピ集』で磨く実践力
tonkotsuboy_com
2
750
TSKaigi Night Talks 2026_TypeScriptでサプライチェーンの整合性を型に閉じ込める
geekplus_tech
0
410
技術的負債解消で開発者の未来を開く- AIの力でコード刷新
kmd2kmd
0
120
Featured
See All Featured
Bash Introduction
62gerente
615
220k
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.2k
KATA
mclloyd
PRO
35
15k
Making Projects Easy
brettharned
120
6.7k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
55k
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
5
1.1k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.3k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
420
HDC tutorial
michielstock
2
720
Building AI with AI
inesmontani
PRO
1
1.1k
Statistics for Hackers
jakevdp
799
230k
Amusing Abliteration
ianozsvald
1
210
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