0

I am seeing this currently

expr self.attributedText = [(NSAttributedString *)([NSAttributedString alloc]) initWithString:@""];
error: <user expression 24>:1:75: no known method '-initWithString:'; cast the message send to the method's return type
self.attributedText = [(NSAttributedString *)([NSAttributedString alloc]) initWithString:@""];
                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~

While creating a NSString works:

(lldb) expr str = [(NSString *)([NSString alloc]) init];
(__NSCFConstantString *) $92 = 0x00007fff8098cd68 @""
Max
  • 29
  • 2
  • as the debugger tells. cast the message to method of return type.. [(NSString*)([NSAttributedString alloc]) initWithString:@""]; but this parentheses cast also.. what about [(NSString*)[NSAttributedString alloc] initWithString:@""]; – Ol Sen Jul 14 '20 at 01:10

2 Answers2

0

just telling NSAttributedString is not an Extension of/or inherited from NSString, instead it has a property called string

and if you can avoid the paranthesis if you do not need a cast.

(lldp) expr str = [[NSAttributedString alloc] initWithString:@""];

should just work

Ol Sen
  • 3,163
  • 2
  • 21
  • 30
0

You can usually avoid the need to cast Foundation methods like this in the expression parser by importing the Foundation module in the debugger.

If you build your code by using the "modules import" form:

import Foundation;

and passing -fmodules when building the .o file (there's also an Xcode setting for this) then the debug info records that your code imported the Foundation module, and lldb will automatically import that.

If you don't use the module form, you can still get lldb to import the module by doing:

(lldb) expr @import Foundation

Doing either of those things, I can run your expression w/o extra casting.

Jim Ingham
  • 25,260
  • 2
  • 55
  • 63