[NSString boolValue]
来源:互联网 发布:windows pe u盘版 编辑:程序博客网 时间:2024/06/04 15:53
If you don’t know NSHipster , you’re missing a real gem among Cocoa blogs.Mattt Thompson has created this journal to weekly lighten unknown Cocoa / Cocoa Touch classes. And Mattt was even on stage at the WWDC 2013, presenting someHidden Gems in Cocoa and Cocoa Touch .
As a tribute to NSHipster, let me present [NSString boolValue]
. Every tailored iOS developer should know this method that converts aBOOL
from a NSString
.
Reading from the doc :
boolValue
Returns the Boolean value of the receiver’s text.- (BOOL)boolValue
Return Value
The Boolean value of the receiver’s text. Returns YES on encountering one of "Y", "y", "T", "t", or a digit 1-9—the method ignores any trailing characters. Returns NO if the receiver doesn’t begin with a valid decimal text representation of a number.
So booValue
can scan and produce these outputs from the followings strings input:
string
boolValue
Y
YES
N
NO
T
YES
F
NO
t
YES
f
NO
1
YES
0
NO
Yes
YES
No
NO
No really no
NO
true
YES
false
NO
To be or not to be
YES
False
NO
3567
YES
0123456789
NO
With this snippet , you can to check the results:
#import <Foundation/Foundation.h>// clang -g -framework Foundation -o bool bool.mint main (void){ NSArray *tests = @[ @"Y", @"N", @"T", @"F", @"t", @"f", @"1", @"0", @"Yes", @"No", @"No really no", @"true", @"false", @"To be or not to be", @"False", @"3567", @"0123456789" ]; NSArray *boolToString = @[@"NO", @"YES"]; for (NSString *test in tests){ NSLog(@"boolValue:\"%@\" => %@", test, boolToString[[test boolValue]]); } return 0;}
Super minimalist and smart algorithm, you can also use boolValue
’s companion: doubleValue
, floatValue
, intValue
, integerValue
, longLongValue
. If you didn’t learn anything, checkNSHipster , I promisse you will learn a lot…
- [NSString boolValue]
- iOS- 基础 [NSString boolValue]结果分析
- NSString
- NSSTring
- NSString
- NSString
- NSString
- NSString
- nsstring
- NSString
- NSString
- NSString
- NSString
- NSString
- NSString
- NSString
- NSString
- NSString
- shell 数组详解
- 欢迎使用CSDN-markdown编辑器
- Win7安装Cent OS 虚拟机
- Eclipse如何查看接口实现类快捷键
- git使用教程
- [NSString boolValue]
- 安居客Android项目架构演进
- c++内存分配及堆与栈的区别
- Vulkan编程指南翻译 第四章 队列和命令 第6节 展开图像
- 动态规划
- 2016 cocoapods的安装和使用以及版本升级遇到的问题
- 腾讯2015年测试开发岗面经
- 飞思卡尔系列MC9S12XS128的中断系统
- Vulkan编程指南翻译 第五章 展现 第1节 拓展