SFeng
SFeng

Reputation: 2276

How to change NSURL variable value while debugging with LLVM in XCode using expr command?

In Xcode, LLDB could change variable value by expr command while debugging(see How to change variables value while debugging with LLVM in XCode?). I used this method to change a string value successfully, but when I change a NSURL variable to a new instance, I got an error:

(lldb) expr url = [NSURL URLWithString:@"www.example.com"];
error: no known method '+URLWithString:'; cast the message send to the method's return type
error: 1 errors parsing expression

How could I change url to a new value? Thanks.

Upvotes: 3

Views: 1525

Answers (2)

Pitoneux
Pitoneux

Reputation: 11

for Swift 5:

expr url = URL(string:"https://www.example.com")! 

Upvotes: 0

HKTonyLee
HKTonyLee

Reputation: 3300

You may try explicitly casting, i.e.

expr url = (NSURL *)[NSURL URLWithString:@"www.example.com"];

Because the LLDB sometimes cannot obtain the return type. For example,

// You should specify the return type here:
expr (int)[UIApplication version]

// instead of
expr [UIApplication version]

Upvotes: 7

Related Questions