nslog

why does this NSLog code print zero's for the values?

爱⌒轻易说出口 提交于 2019-12-11 07:28:55
问题 Why does this objective-c code print 0's for the values, where as in debugger I can see they have non-0 values: Code CGRect currFrame = label.frame; currFrame.origin.y = currVertPos; currFrame.origin.x = 0; currFrame.size.height = expectedLabelSize.height; currFrame.size.width = maxWidt h; NSLog(@" currFrame dimensions:x/y/height/width = %d / %d / %d / %d", 0, currVertPos, expectedLabelSize.height, maxWidth); What is Printed currFrame dimensions:x/y/height/width = 0 / 0 / 0 / 0 回答1: Because

Objective-C Calculating string value

夙愿已清 提交于 2019-12-11 03:21:26
问题 This is my main: int x=0; NSString *new=[[NSString alloc]initWithString:@"9+4"]; x=[new intValue]; NSLog(@"hi %i",x); This results in 9.. .since giving the intValue of a string will read only numbers and stops when the character is not a digit. So how can i print the result of my string and get a 13 instead?? 回答1: Change this line NSString *new=[[NSString alloc]initWithString:@"9+4"]; to NSString *new=[NSString stringWithFormat:@"%f",9+4]; 回答2: Actually, NSExpression was made just for this:

Nslog timestamp

我们两清 提交于 2019-12-11 02:26:27
问题 I want to nslog the device motion timestamp property . The device motion is in the class CMMotionManager.devicemotion.timestamp Any ideas. 回答1: Edit : Please see Nicolas Lauquin's answer. Per the comments, the following solution is not correct but is retained here for history (and because I can't delete it since it is currently marked accepted). The timestamp property is an NSTimeInterval , so you should be able to do: NSLog(@"Motion at time: %@", [NSDate

Customizing NSLog Function on iPhone

[亡魂溺海] 提交于 2019-12-11 02:10:36
问题 I know that it's possible to do method swizzling for Selectors and Methods in Objective C. Is it possible to swizzle functions like NSLog to our custom function. I wanted to add some extra functionality along with NSLog in the custom function. EDIT: I finally ended up using another function which will call NSLog internally. #define NSLog(...) CustomLogger(__VA_ARGS__); void CustomLogger(NSString *format, ...) { va_list argumentList; va_start(argumentList, format); NSMutableString * message =

What does “autoresize = W+H;” mean in NSLog output of a UIView object

回眸只為那壹抹淺笑 提交于 2019-12-10 23:44:00
问题 Code: NSLog(@"[self view] = %@", [self view]); Output: [self view] = <UIView: 0xca2bfc0; frame = (0 44; 320 588); autoresize = W+H; autoresizesSubviews = NO; layer = <CALayer: 0xca1d7e0>> I tried to [[self view] setFrame:CGRectMake(0, 64, 320, 568 + 64)]; , but view's frame is still frame = (0 44; 320 588). So I NSLog the [self view] to see if there is some autoresize constraints there. But don't know what does the above notation mean. 回答1: This is the log description of the UIView

how do I specify the DEBUG definition in the project build settings?

馋奶兔 提交于 2019-12-10 23:38:55
问题 I'm trying to implement the logging approach at http://www.cimgf.com/2010/05/02/my-current-prefix-pch-file/ . I'm not sure how to complete the step: Therefore the first line is a switch to see if we are in debug mode. I set this value in the build settings of my project. If you look under the “Preprocessor Macros” section you can set the DEBUG definition there. This is to cater for a "#ifdef DEBUG" entry (I'm only giving first line) in your code. QUESTION: How do I actually setup this DEBUG

Getting object name in Objective-c

为君一笑 提交于 2019-12-10 19:29:12
问题 suppose i have a class Foo and an instance of this class myFoo: Foo *myFoo; is there any method "dispalyFooObjectName" that can display the name of the object, for exmample : NSLog(@"i was called from %s", [myFoo dispalyFooObjectName]); and the result will be : i was called from myFoo 回答1: In most programming languages objects don't have names. Just because some variable myFoo references your object, doesn't mean that your object is "called" myFoo . And in most C-based languages variable

Xcode, Why are some NSLog entries omitted from the console?

痴心易碎 提交于 2019-12-10 18:38:34
问题 I'm just beginning to learn IOS development. Everytime I run this program, the console does not always display my NSLogs. #import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { @autoreleasepool { NSMutableArray *items = [[NSMutableArray alloc] init]; [items addObject:@"One"]; [items addObject:@"Two"]; [items addObject:@"Three"]; [items insertObject:@"zero" atIndex:0]; NSLog(@"Object at 0 is %@", [items objectAtIndex:0]); NSLog(@"Object at 1 is %@", [items objectAtIndex:1]

Dynamic assigning of value to macro function .pch file and checking condition .pch file

独自空忆成欢 提交于 2019-12-10 11:27:21
问题 .pch as its name shows pre-compiler header, I have defined a macro in the file so that app can decide in the very beginning of the app compilation. What I need is, possible to load any macro by assigning the values dynamically something like NSUserDefaults and checking the condition in .pch file itself. If user disable logs from screen (switch), there should be no logs else... it can print logs, least bother about Debug/Release mode. I have " #define NSLog(FORMAT, ...) TFLog((@"%s [Line %d] "

NSLog(…) improper format specifier affects other variables?

一世执手 提交于 2019-12-10 11:25:25
问题 I recently wasted about half an hour tracking down this odd behavior in NSLog(...): NSString *text = @"abc"; long long num = 123; NSLog(@"num=%lld, text=%@",num,text); //(A) NSLog(@"num=%d, text=%@",num,text); //(B) Line (A) prints the expected "num=123, text=abc", but line (B) prints "num=123, text= (null) ". Obviously, printing a long long with %d is a mistake, but can someone explain why it would cause text to be printed as null? 回答1: You just messed up memory alignment on your stack. I