1
votes

The following code works fine in Swift2.2 of iOS7+, Swift3.0 of iOS8+, would crash only in Swift3.0 iOS7. let context = CIContext(options: nil)

The console info:

-[CIContext initWithOptions:]: unrecognized selector sent to instance 0x147366e0 2016-10-25 17:32:27.903 CMBMobile DEV[1017:4403] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CIContext initWithOptions:]: unrecognized selector sent to instance 0x147366e0'

I tried to change it into let context = CIContext() But it seems the instance of context is not been initialize for the address of it is 0x00000000.And when I call context.createCGImage(ciimage, from: originRect) returns unexpected nil.

2

2 Answers

0
votes

As Swift 3 is compatible only for iOS 8+, it is crashing.

0
votes

In Swift3.0, this is a bug by Apple. You can create a Category for CIContext.

#import <CoreImage/CoreImage.h>

@interface CIContext (FixBug)
+ (CIContext *)swiftContextWithOptions:(NSDictionary<NSString *, id> *)options;

@end


#import "CIContext+FixBug.h"
@implementation CIContext (FixBug)
+ (CIContext *)swiftContextWithOptions:(NSDictionary<NSString *,id> *)options {
    return [CIContext contextWithOptions:options];
}
@end

And you should use this function.

let context = CIContext.swiftContext(options: [kCIContextUseSoftwareRenderer: false])