Lumialxk Lumialxk - 13 days ago 15x
Swift Question

'-[CIContext initWithOptions:]: unrecognized selector sent to instance

I used this to generate a big image:

let context = CIContext(options: nil)
let bitmapImage: CGImageRef = context.createCGImage(image, fromRect: extent)!
CGContextSetInterpolationQuality(bitmapRef, CGInterpolationQuality.None)
CGContextScaleCTM(bitmapRef, scale, scale);
CGContextDrawImage(bitmapRef, extent, bitmapImage);
let scaledImage: CGImageRef = CGBitmapContextCreateImage(bitmapRef)!
return UIImage(CGImage: scaledImage)

It worked well in iOS 9 and 10 but not 8. I got this in the debugger:

Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '-[CIContext initWithOptions:]:
unrecognized selector sent to instance 0x7f868d5dc8e0'

In addition. I tried to use
let context = CIContext()
instead. But I got nil in the second line. I'm using Xcode 8 and Swift 2.3. Please help me with this! Thanks!


I have no idea if this will work, but we should try it: let's write that line in Objective-C. So:


#import <Foundation/Foundation.h>
#import <CoreImage/CoreImage.h>

@interface ContextMaker : NSObject

+ (CIContext*) makeMeAContext;



#import "ContextMaker.h"

@implementation ContextMaker

+ (CIContext*) makeMeAContext {
    return [CIContext contextWithOptions:nil];


Bridging Header:

#import "ContextMaker.h"


let c = ContextMaker.makeMeAContext()

It will only take you a moment to try it, so give it a go and see if we can get past that troublesome line...