How to print Boolean flag in NSLog?
Here's how I do it:
BOOL flag = YES;
NSLog(flag ? @"Yes" : @"No");
?:
is the ternary conditional operator of the form:
condition ? result_if_true : result_if_false
Substitute actual log strings accordingly where appropriate.
how to print out bool in objective c
%@
is for objects. BOOL
is not an object. You should use %d
.
It will print out 0
for FALSE/NO and 1
for TRUE/YES.
How do I print out Bool values with words?
Try this....
'%d', 0 like false, 1 like true
BOOL b;
NSLog(@"Bool value: %d",b);
or
NSLog(@"bool %s", b ? "true" : "false");
Hope i helped.
Issue with NSLog when printing BOOL type
%@ is used to print the description of objects that are descendants of the NSObject class, this however can be overwritten to make your objects print whatever you want.
Unless autoFlag is an object it will crash your program. It is very common to get these type of errors in NSLog Statements since the compiler cant tell what kind of "thing" you want to print and most of the time it wont be able to know before hand (there are some exceptions in where it will tell you that you are using the wrong identifier).
If what you want to see is something like "True" or "YES" then you need something like
NSLog(@"Auto Flag: %@",object.autoFlag? @"True":@"False");
How to print BOOLs
NSLog(parsingResult ? @"YES" : @"NO");
NSLog symbol print on console?
try this
NSLog(@"str : %%");
Thanks
Use NSLog print variable,why add a nil?
The signature of NSLog
is void NSLog (NSString *format, ...);
.
So the first argument is rather a format instead of a literal string. The second (and all following) arguments are the substitution values for the format string.
You should not replace the format string with the string you want to log. If your string contains format specifiers like %d
NSLog
will try to replace them but will fail to do so as you have not entered a substitution.
You should always log with NSLog(@"%@", string)
when you want to log string
.
Related Topics
How to Keep Uiswitch State When Changing Viewcontrollers
Swiftui Generic Pull to Refresh View
How to Print Boolean Flag in Nslog
Expanding and Collapsing Uitableviewcells with Datepicker
Why Is My iOS App Not Showing Up in Other Apps' "Open In" Dialog
Xcode 8 - Missing Files Warnings
Custom Uifont Baseline Shifted
How to Programmatically Use iOS Voice Synthesizers? (Text to Speech)
Play Mp3 Files with iPhone Sdk
Nsinternalinconsistencyexception, Reason: Could Not Load Nib in Bundle
Conditionally Import a Framework (Such as Speech) Based on iOS Version in Swift
Programmatically Go Back to Previous Viewcontroller in Swift
Avplayer Stops Playing and Doesn't Resume Again
Dismissing Uialertviews When Entering Background State
Modify Uiimage Renderingmode from a Storyboard/Xib File
Set Uitableview's Height to the Height of Its Content with Auto Layout
In Swiftui, How to Use Uihostingcontroller Inside an Uiview or as an Uiview