How to create and use temp NSRange in lldb?

▼魔方 西西 提交于 2019-12-05 01:45:48

Creating a NSRange in the debugger works fine when working in a OS X project but it doesn't for iOS projects. The reason it doesn't work on iOS is that even though Foundation provides the header file in which the struct is declared, it doesn't expose any corresponding symbol. Basically, on iOS, NSRange is just a forward declaration and I do not know the real symbol for the implementation.

I needed to create an NSRange recently whilst trying to debug some code and came across this thread. It is currently possible to do this 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, as leaving off (NSRange) on the second example results in the same error), but it works now.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!