[CIContext initWithOptions:]: unrecognized selector sent to instance 0x170400960 in xcode8

白昼怎懂夜的黑 提交于 2019-12-22 03:33:08

问题


run in ios8.3 ,but run in ios9 or 10 hasn't this problem.

-[CIContext initWithOptions:]: unrecognized selector sent to instance 0x170400960
2016-09-19 18:08:21.025 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CIContext initWithOptions:]: unrecognized selector sent to instance 0x170400960'
*** First throw call stack:
(0x186d8c2d8 0x1985b00e4 0x186d933a4 0x186d90154 0x186c92ccc 0x1001c1e74 0x1001c1b7c 0x1001c143c 0x1001c1cfc 0x100311e0c 0x1003116d0 0x1001d7690 0x101f3025c 0x101f2fc08 0x101eee29c 0x103db8fd4 0x103db8f94 0x103dbdc28 0x186d437f8 0x186d418a0 0x186c6d2d4 0x1904836fc 0x18b832fac 0x100401fd8 0x198c2ea08)
libc++abi.dylib: terminating with uncaught exception of type NSException

回答1:


If you look at the crash report, it seems that Xcode 8 has some issue converting the Swift method CIContext(options: [String : Any]?) to its Objective-C counterpart + (CIContext *)contextWithOptions:(NSDictionary<NSString *,id> *)options;.

Instead it is converted as -[CIContext initWithOptions:] hence the unrecognized selector.

One possible workaround is to declare an Objective-C category like this:

@interface CIContext (Workaround)

+ (CIContext *)yourprefix_contextWithOptions:(NSDictionary<NSString *, id> *)options;

@end

@implementation CIContext (Workaround)

+ (CIContext *)yourprefix_contextWithOptions:(NSDictionary<NSString *, id> *)options {
    return [CIContext contextWithOptions:options];
}

@end

Then import this category in your module bridging header and replace your original CIContext init call with the one from this category.

I imagine this is a compilation issue that can be fixed with an Xcode update. In the meantime, this workaround may be helpful.



来源:https://stackoverflow.com/questions/39570644/cicontext-initwithoptions-unrecognized-selector-sent-to-instance-0x170400960

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!