1

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.

Janmenjaya
  • 4,149
  • 1
  • 23
  • 43
Xingxing
  • 580
  • 1
  • 6
  • 17
  • It's probably a Xcode 8 bug.[cicontext-initwithoptions-unrecognized-selector-sent-to-instance](http://stackoverflow.com/questions/39570644/cicontext-initwithoptions-unrecognized-selector-sent-to-instance-0x170400960) fix it – Xingxing Oct 26 '16 at 00:41

2 Answers2

0

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

Punit
  • 1,330
  • 6
  • 13
0

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])
ParadiseDuo
  • 58
  • 1
  • 3