I've got something like this:
NSArray* titleColors = #[defaultColorForTitles, defaultColorForTitles, defaultColorForTitles]];
If I NSLog it out, I get:
2015-02-09 15:26:21.984 project[27352:1574376] (
6c6c6c,
red,
blue
)
Yay!
But if I set a breakpoint at the next line and hover over the variable, instead of seeing the array values (like I'd expect), it shows nil. Is this expected? Is my Xcode broken? What's going on?
Are you running a debug build? When hit your break point, does NSLog print out the value? If it does print out, but your inspector shows nil. It can be you are running a released build and compiler made an optimization there (mostly because that line is the last use of titleColors). That's my guess based on current information.
Related
I'm facing big issues when trying to print out Objective C properties in many situations when I'm almost certainly sure it SHOULD work.
Consider the following setup:
The view controller's property has strictly set class (Card *), but still, LLDB outputs an parsing error where subproperty cannot be found on object of type id.
Having an object property defined on a view controller (see points 5 & 6):
stop at breakpoint inside the controller code (f.e. in -viewDidAppear: method)
try to print out the property itself with po _card (points 1 & 2)
try to print out its subproperty with po _card.offlineURL (points 3 & 4)
an LLDB parsing error occurs
Printing out via [_card offlineURL] prints out proper object description as LLDB sends a message to Card object with no class check.
Definition of object property on the controller declares non-id class, though (point 5).
I'm expecting LLDB to print out the property object's subproperty description, NSString containing URL string in this case, but this annoying LLDB error occurs instead.
This is just a single example from many. Sometimes it affects direct property printout, numbers printing etc. These issues are way more frequent since integration of Swift began, being worse with every new version of Xcode since 6.2, including the latest 7.2.
This happens in my Objective C project in many situations, though sometimes it works fine in different cases.
Do you know about any work-arounds or fixes for this issue? I've already filed a report on Apple Bug Reporter, but this will certainly take time for Apple to even notice.
The most likely problem given the info in your question is that we don't actually have debug information for _card.
The lldb command:
(lldb) image lookup -t Card
will tell you whether lldb had debug information for Card available to it. If this doesn't find anything, then maybe some part of your project isn't getting built with debug info. If the command does find some correct definition of Card, then it must be that the debug info for the _card ivar is not getting hooked up to this type correctly.
If there is a definition of Card, then the workaround:
(lldb) po ((Card *) _card).offLineURL
is available.
For future reference, there are two other bits of behavior that are probably complicating your attempt to figure out what is going on here:
1) (w.r.t. picture 3) The Xcode IDE uses its built-in indexer for auto completion in the debug window as well as the Source Code editor. But the debugger runs off debug information, since we need to be able to debug things that aren't built in Xcode. So the fact that auto-completion can find a name in an expression doesn't tell you anything about what lldb will do.
2) (w.r.t. picture 2) po force-casts the expression you are trying to "po" to an ObjC object (i.e. "id") and then calls its description method. The description method of an ObjC object that doesn't override description prints the type name and the address. So lldb didn't need to know the type of the _card ivar to get the output you saw. We only start to need types when the expression is more complex and involves accesses to ivars or properties of an ObjC object in the expression.
Note also, by default if you do:
(lldb) print _card
lldb will evaluate the expression "_card", find it resolves to a pointer of at least type id, then follow that pointer's isa pointer into the ObjC runtime to figure out what the dynamic type is. So it is likely to print Card * in this case.
But the expression parser hasn't yet been taught to resolve the dynamic type of sub-expressions within the expression parser in mid-parse. That would actually be quite a trick... So if it doesn't know the full type of _card, then:
(lldb) print _card.offlineURL
isn't going to work, since id does indeed not have a property of that name.
You can work around this by doing:
(lldb) print _card
$0 = (Card *) 0x12345678
Then:
(lldb) print $0.offlineURL
since the result variable captures the full dynamic type information, that will also be available in subsequent expressions.
I'm running into a strange crash that's difficult to reproduce. For instance, out of the past 35 runs of the app, this crash happened once. I'm not sure of the exact steps to repro unfortunately.
The crash report shows:
SIGSEGV
Remotely-[NetworkCall handleRequestFinished]
in NetworkCall.m on Line 232
line 232 is:
_startBlock = nil;
and that property is defined as:
typedef void (^NetworkCallStartBlock)();
#property(copy, nonatomic) NetworkCallStartBlock startBlock;
The one time i was able to repro the bug w/ the debugger attached, printing out _startBlock to console showed its value was already nil when attempting to assign nil.
Any thoughts?
_startBlock = nil; change to self.startBlock = nil
the latter one make your block release and safely set the property to nil.
JosephH's comment above was correct. setting the already nil'd value to nil was happening after self was dealloc'd, so it was dereferencing self that was the issue. the dealloc for this class wasn't properly setup to nil everything out, so fixing that solved the issue. Thanks all for the input and tracking it down
I am trying to add an object to my mutable array but when when I do it crashes. I am sure that my array has been alloc and init.
Here is my code:
I have tried to figure out what is wrong, it seems my code works perfectly fine if I out comment the line [self.tableView insertRowsAtIndexPaths...]
The only problem is that my tableView is not updating then :'( (if I out comment the line).
Here is my error msg:
And here is my consol when I have out commented inserRowsAtIndexPaths... line:
As you can see everything seems to work fine.
Extra info:
I don't know if you need it but here is my UITableViewDataSource :)
Thank you
Anders
I believe your problem is that you never alloc-init'd your array. If that's the case, you're trying to stuff items into something that just isn't there. You say you're sure that it has been already, but I would do some debugging to make double sure. That was what caused me to get this same error message; I had accidentally deleted my init method earlier.
When I take look at your logs, I can see this 'Indexpath = 0' which means that you have nothing in your Array (self.budgets.items), try to debug your dataSource array(Actual data you want to display on tableView) first.
I have a UIWebView in which I set content offset at some point:
myWebView.scrollView.contentOffset = CGPointZero;
It turns out afterwards that this view is scrolled to the bottom of its content. How can I figure out which part of code sets that offset? I miss data breakpoints and watchpoints on it. But how can i do it in actual Xcode?
In Xcode 4.5, in the locals window, you can turn out objects to see the member ivars, right-click/control-click on the ivar of interest and hit "Watch " and anything that modifies that ivar in that object will stop execution. Alternatively, you can add a watchpoint from the debugger console like this,
(lldb) watch set variable myWebView.scrollView.contentOffset
or
(lldb) w s v myWebView.scrollView.contentOffset
(shortest unique command name is always valid in command line lldb)
I have see this in sample objective c code before, but can't find it now and all the searches come back with irrelivent results.
I want to write debug messages to the Xcode output window. What's the command to do that? Basically like System.Diagnostics.Debug.WriteLine for C#.
NSLog(#"Your message here");
...should do it.
To include data from variables you can use string formatting, e.g:
NSLog(#"Value of string is %#", myNSString);
There are a bunch of different string format specifiers, you can look at them here: https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/Strings/Articles/formatSpecifiers.html
You are looking for NSLog. Calling
NSLog(#"Message");
will print Message on the console.
See here for more info about how to use string formatters to print the values of variables like in the examples below:
NSLog(#"This is a string: #", aString);
NSLog(#"This is an int: %d", anInt);
It's better to write the debug messages using debugger breakpoints instead of cluttering your code with NSLog messages. Breakpoints will also save you from having to remove all those log messages when you ship your app.
To do this, set a breakpoint in Xcode, double-click on it, and click the Add Action button in the pop-up window. Select "Log Message" and type your message. Check the "Automatically continue after evaluating" check box at the bottom to keep it from pausing execution on the breakpoint