I have defined a method appendString method in a NSMuatableAttributedString category like this:
@implementation NSMutableAttributedString (HTML)
// appends a plain string extending the attributes at this position
- (void)appendString:(NSString *)string
{
NSParameterAssert(string);
NSUInteger length = [self length];
...
And this method is worked well in iOS17 and before .
But when it cames iOS18 . this appendString will not be called.
So I doubt maybe there is a system-defined appendString already.
So I write a demo in empty project to print all the NSMuatableAttributedString method in iOS18 like these:
@interface ViewController ()
@end
@implementation ViewController
void printNSStringCategories() {
unsigned int count;
Class nsStringClass = [NSMutableAttributedString class];
// 获取所有的方法
Method *methods = class_copyMethodList(nsStringClass, &count);
for (unsigned int i = 0; i < count; i++) {
SEL selector = method_getName(methods[i]);
NSString *methodName = NSStringFromSelector(selector);
NSLog(@"NSMutableAttributedString method: %@", methodName);
}
free(methods);
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
printNSStringCategories();
}
And test it in my iPhone (iOS18.2) , the log will printed
NSMutableAttributedString method: appendString:withAttributes:
NSMutableAttributedString method: cr_appendStorage:fromRange:
NSMutableAttributedString method: cr_appendString:
NSMutableAttributedString method: appendString:withAttributes:
NSMutableAttributedString method: appendString:
So it seems a appendString:
is aleady defined in system SDK .
But the weird thing is when I run this code in the Xcode simulator (iOS18.1) this appendString:
will not print .
1 Is it a bug of SDK ? because the appendString: only exist in device-build , and not exist in simulator-build?
two more furthur question:
2.1 if the SDK contains appendString: already , why the appendString: defined
in my category not cause the duplicate symbol error when compile
2.2 As the question 2.1 said , there maybe same symbols in runtime . Is there any way to find the framework/library which defined those same-name symbols ? (e.g: there are two appendString:withAttributes: in
the log , I want to find the two places define each appendString:withAttributes: exactly)