- macOS 11.5.2
- Xcode 13.2.1
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
#import <iostream>
int main(int argc, const char * argv[]) {
@autoreleasepool {
Class clazz = NSClassFromString(@"NSString");
uint32_t count = 0;
objc_property_t* properties = class_copyPropertyList(clazz, &count);
for (uint32_t i = 0; i < count; i++){
const char* name = property_getName(properties[i]);
std::cout << name << std::endl;
}
free(properties);
}
return 0;
}
I will take some snippets of the output:
hash
superclass
description
debugDescription
hash
superclass
description
debugDescription
vertexID
sha224
NS_isSourceOver
hash
superclass
description
debugDescription
...
From the output, we can find that attributes such as hash, description, superclass, etc. will appear repeatedly several times, while some attributes (such as UTF8String) do not appear in the result list. How should I get the list of properties correctly? I would appreciate it.
Aucun commentaire:
Enregistrer un commentaire