iOS 5: Make NSString Category include NSCFConstantString?

后端 未结 3 929
鱼传尺愫
鱼传尺愫 2020-12-17 18:49

I have an NSString category class (NSString+URLEncoding.h). I am running into and unknown selector crash, because the string I am calling the categ

相关标签:
3条回答
  • 2020-12-17 19:13

    Just spent 30 minutes figuring out exactly the same issue. After fiddling with linker I found out that the category wasn't present in Compile Sources list in my target's Build Phases. Be sure to check it's there.

    0 讨论(0)
  • 2020-12-17 19:18

    There's an issue with the linker that can cause its dead-code stripping to completely omit any object files that only contain obj-c categories (or that are otherwise unreferenced). Theoretically passing the -ObjC flag to the linker should fix this, but that doesn't seem to always work. You can work around this issue by providing the -all_load linker flag, which will cause the linker to always link in all object files.

    Note that you might have to set -all_load on the parent project if your category is part of a sub-project or library that you-re including somewhere.

    Update: I believe -ObjC is reliable now and has been for years so you can stop using -all_load for this issue.

    0 讨论(0)
  • 2020-12-17 19:25

    __NSCFConstantString is a subclass of NSString, so any categories on NSString apply to __NSCFConstantString too.

    Either you're not linking in your category, or your category doesn't define a URLEncodedString method in its @implementation.

    0 讨论(0)
提交回复
热议问题