Hi,

I'm beginning to feel this above my pay grade as I can't seem to work it out.

I have a framework in Objective-C. I've been writing some tests for it, and to 
make life fun I've been writing the tests in Swift.

I have a property of a class in the objective-c framework declared like so:

@property (nonatomic, copy) CGImageRef (^createImage)(NSDictionary *);

In my tests I'm trying to write a function that I can assign to the property.

In the most basic form the function looks like this, I'm ignoring the passed in 
dictionary for the purposes of asking this question:

func createCGImage2(dictionary: [NSObject:AnyObject]) -> CGImage {
    let jpegURL = NSBundle.mainBundle().URLForResource("myimage", 
withExtension:"jpg")
    let imageSource = CGImageSourceCreateWithURL(jpegURL, nil)!
    let theImage = CGImageSourceCreateImageAtIndex(imageSource, 0, nil)
    return theImage
}

When I try to set the property with the function I get:

error: cannot convert the expression's type '([NSObject : AnyObject]) -> 
Unmanaged<CGImage>!' to type '(([NSObject : AnyObject]!) -> 
Unmanaged<CGImage>!)!?'

Now, if I have a function declared like so:

func createCGImageFromDictionary(dictionary: [NSObject:AnyObject]!) -> 
Unmanaged<CGImage>!

error: cannot convert the expression's type '([NSObject : AnyObject]!) -> 
Unmanaged<CGImage>!' to type '(([NSObject : AnyObject]!) -> 
Unmanaged<CGImage>!)!?'

I'm still a long way off. There's an extra () in there and an extra !? at the 
end that I really don't know how to interpret. Also I don't know how to convert 
the result of CGImageSourceCreateImageAtIndex to a Unmanaged<CGImage> as a 
return value.

I've been through various bits of the documentation, but something isn't 
clicking so that I understand how this stuff works so that I can try and solve 
it.

Kevin

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to