有办法打印值布尔标志在NSLog?
当前回答
//assuming b is BOOL. ternary operator helps us in any language.
NSLog(@"result is :%@",((b==YES)?@"YES":@"NO"));
其他回答
注意,在Swift中,你可以这样做
let testBool: Bool = true
NSLog("testBool = %@", testBool.description)
这将记录testBool = true
你可以这样做:
BOOL flag = NO;
NSLog(flag ? @"YES" : @"NO");
苹果的FixIt提供了%hhd,它正确地给了我BOOL的值。
%d, 0为假,1为真。
BOOL b;
NSLog(@"Bool value: %d",b);
or
NSLog(@"bool %s", b ? "true" : "false");
基于数据类型%@的变化如下
For Strings you use %@
For int you use %i
For float and double you use %f
//assuming b is BOOL. ternary operator helps us in any language.
NSLog(@"result is :%@",((b==YES)?@"YES":@"NO"));
推荐文章
- 如何删除默认的导航栏空间在SwiftUI导航视图
- 如何在iOS中使用Swift编程segue
- Swift -整数转换为小时/分钟/秒
- Swift:声明一个空字典
- 为什么ARC仍然需要@autoreleasepool ?
- 在成功提交我的应用程序后,“太多符号文件”
- 首先添加一个UIView,甚至是导航栏
- 我如何改变UIButton标题颜色?
- 如何从UIImage (Cocoa Touch)或CGImage (Core Graphics)获取像素数据?
- 在Swift中如何调用GCD主线程上的参数方法?
- NSLayoutConstraints是可动画的吗?
- iOS -构建失败,CocoaPods无法找到头文件
- Xcode 4挂在“附加到(应用程序名称)”
- CFNetwork SSLHandshake iOS 9失败
- 请求失败:不可接受的内容类型:文本/html使用AFNetworking 2.0