How to create and use temp NSRange in lldb?

NSRange is just a C. structure. I want to create a temporary in lldb in Xcode at a breakpoint.

In particular, for use in the NSArray method objectAtIndex:inRange:

This does not work.

 (lldb) expr NSRange $tmpRange = (NSRange){0,4} (lldb) expr $tmpRange (NSRange) $tmpRange = location=0, length=4 (lldb) expr -o -- [items indexOfObject:item4 inRange:$tmpRange] error: no matching constructor for initialization of 'NSRange' (aka '_NSRange') error: 1 errors parsing expression 

My code has an NSRange var named badRange at the breakpoint and passes it to work. Thus:

 (lldb) expr -o -- [items indexOfObject:item4 inRange:badRange] 0x7fffffffffffffff (lldb) expr badRange (NSRange) $1 = location=0, length=3 

What's happening?

Thanks.

+5
source share
2 answers

Creating NSRange in the debugger works fine when working in an OS X project, but it is not for iOS projects. The reason it doesn't work on iOS is because although Foundation provides a header file in which the structure is declared, it does not display the corresponding character. Basically, on iOS, NSRange is just a declaration, and I don't know the real symbol to implement.

+3
source

I needed to create NSRange recently, trying to debug some code and came across this thread. Currently, this can be done for iOS projects using Xcode 8.3.2 with the following syntax.

 po [@"test words here" stringByReplacingOccurrencesOfString:@"\\s" withString:@"" options:1024 range:(NSRange){0,15}] 

This also works:

 expr NSRange $tmpRange = (NSRange){0,15} po [@"test words here" stringByReplacingOccurrencesOfString:@"\\s" withString:@"" options:1024 range:(NSRange)$tmpRange] 

Not sure when this was fixed (or if it ever was, since holding (NSRange) in the second example leads to the same error), but now it works.

+1
source

All Articles