objcio / issue-16-functional-apis

Example playground for the article http://www.objc.io/issue16/functional-swift-apis.html
13 stars 3 forks source link

Convenience initializer for CIFilter is not working #2

Open etrep opened 9 years ago

etrep commented 9 years ago

Hello, I'm trying to follow along the code in this article and I am running into some issues.

I'm on Yosemite 10.10.1, running Xcode 6.1 (6A1052d).

When I initially opened the project and tried building it, I was getting the following compile error: /Users/eric/Projets/Learning/Objcio/issue-16-functional-apis-master/FunctionalCoreImage/CoreImage.swift:39:22: Cannot invoke 'init' with an argument list of type '(name: StringLiteralConvertible, parameters: $T5)'

After a bit of digging around (I'm still pretty new with Swift), I figured out that I apparently needed to add an exclamation mark after the CIColor constructor (although I'm not quite sure I understand why):

    let filter = CIFilter(name:"CIConstantColorGenerator", parameters: [kCIInputColorKey: CIColor(color: color)!])

This allows the build to complete successfully, but then when trying to run the program, I get an exception thrown in the CIFilter's convenience init method:

2014-11-27 08:54:57.060 FunctionalCoreImage[14200:7077865] +[NSObject customAttributes]: unrecognized selector sent to class 0x10cd54d28
2014-11-27 08:54:57.929 FunctionalCoreImage[14200:7077865] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[NSObject customAttributes]: unrecognized selector sent to class 0x10cd54d28'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010ad9ef35 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x000000010cb5fbb7 objc_exception_throw + 45
    2   CoreFoundation                      0x000000010ada5f4d +[NSObject(NSObject) doesNotRecognizeSelector:] + 205
    3   CoreFoundation                      0x000000010acfe27c ___forwarding___ + 988
    4   CoreFoundation                      0x000000010acfde18 _CF_forwarding_prep_0 + 120
    5   CoreImage                           0x000000010b19faf5 -[CIFilterClassDescription initWithClass:] + 182
    6   CoreImage                           0x000000010b19f9e4 +[CIFilterClassDescription classDescriptionForClass:] + 147
    7   CoreImage                           0x000000010b19fea0 -[CIFilterClassDescription initWithClass:] + 1121
    8   CoreImage                           0x000000010b19f9e4 +[CIFilterClassDescription classDescriptionForClass:] + 147
    9   CoreImage                           0x000000010b19c959 -[CIFilter inputKeys] + 22
    10  CoreImage                           0x000000010b19c848 -[CIFilter dealloc] + 84
    11  libobjc.A.dylib                     0x000000010cb7428e _ZN11objc_object17sidetable_releaseEb + 236
    12  FunctionalCoreImage                 0x000000010abb7f67 _TFE19FunctionalCoreImageCSo8CIFiltercfMS0_FT4nameSS10parametersGVSs10DictionarySSPSs9AnyObject___S0_ + 1335
    13  FunctionalCoreImage                 0x000000010abb86c7 _TToFE19FunctionalCoreImageCSo8CIFiltercfMS0_FT4nameSS10parametersGVSs10DictionarySSPSs9AnyObject___S0_ + 135
    14  FunctionalCoreImage                 0x000000010abb901c _TTDFE19FunctionalCoreImageCSo8CIFiltercfMS0_FT4nameSS10parametersGVSs10DictionarySSPSs9AnyObject___S0_ + 124
    15  FunctionalCoreImage                 0x000000010abb7a21 _TFE19FunctionalCoreImageCSo8CIFilterCfMS0_FT4nameSS10parametersGVSs10DictionarySSPSs9AnyObject___S0_ + 129
    16  FunctionalCoreImage                 0x000000010abb9959 _TFF19FunctionalCoreImage4blurFSdFCSo7CIImageS0_U_FS0_S0_ + 1097
    17  FunctionalCoreImage                 0x000000010abbacf8 _TFC19FunctionalCoreImage14ViewController11viewDidLoadfS0_FT_T_ + 968
    18  FunctionalCoreImage                 0x000000010abbaf42 _TToFC19FunctionalCoreImage14ViewController11viewDidLoadfS0_FT_T_ + 34
    19  UIKit                               0x000000010b9cca90 -[UIViewController loadViewIfRequired] + 738
    20  UIKit                               0x000000010b9ccc8e -[UIViewController view] + 27
    21  UIKit                               0x000000010b8ebca9 -[UIWindow addRootViewControllerViewIfPossible] + 58
    22  UIKit                               0x000000010b8ec041 -[UIWindow _setHidden:forced:] + 247
    23  UIKit                               0x000000010b8f872c -[UIWindow makeKeyAndVisible] + 42
    24  UIKit                               0x000000010b8a3061 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 2628
    25  UIKit                               0x000000010b8a5d2c -[UIApplication _runWithMainScene:transitionContext:completion:] + 1350
    26  UIKit                               0x000000010b8a4bf2 -[UIApplication workspaceDidEndTransaction:] + 179
    27  FrontBoardServices                  0x000000011200d2a3 __31-[FBSSerialQueue performAsync:]_block_invoke + 16
    28  CoreFoundation                      0x000000010acd453c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
    29  CoreFoundation                      0x000000010acca285 __CFRunLoopDoBlocks + 341
    30  CoreFoundation                      0x000000010acca045 __CFRunLoopRun + 2389
    31  CoreFoundation                      0x000000010acc9486 CFRunLoopRunSpecific + 470
    32  UIKit                               0x000000010b8a4669 -[UIApplication _run] + 413
    33  UIKit                               0x000000010b8a7420 UIApplicationMain + 1282
    34  FunctionalCoreImage                 0x000000010abbc62e top_level_code + 78
    35  FunctionalCoreImage                 0x000000010abbc66a main + 42
    36  libdyld.dylib                       0x000000010d339145 start + 1
    37  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

Is anyone else encountering this issue?

etrep commented 9 years ago

See also https://github.com/objcio/functional-programming-in-swift/issues/42

aoakenfo commented 9 years ago

I'm running Xcode 6.2 beta-4 with:

let filter = CIFilter(name: "CIConstantColorGenerator", withInputParameters: [kCIInputColorKey: CIColor(color: color)!])

And it runs with nothing displayed, except the following output:

This NSLayoutConstraint is being configured with a constant that exceeds internal limits. A smaller value will be substituted, but this problem should be fixed. Break on void _NSLayoutConstraintNumberExceedsLimit() to debug. This will be logged only once. This may break in the future.

Which suggests that the size is WAY too big, so I added the crop extents and it works:

func colorGenerator(color: UIColor) -> Filter { return { image in let filter = CIFilter(name: "CIConstantColorGenerator", withInputParameters: [kCIInputColorKey: CIColor(color: color)!]) return filter.outputImage.imageByCroppingToRect(image.extent()) } }