Created
October 17, 2014 16:38
-
-
Save SheffieldKevin/a06907e163885f249548 to your computer and use it in GitHub Desktop.
Revisions
-
Sheffield Kevin created this gist
Oct 17, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ // // CreateImageProtocol.h // test // // Created by Kevin Meaney on 17/10/2014. // Copyright (c) 2014 Kevin Meaney. All rights reserved. // #import <Foundation/Foundation.h> @protocol CreateImageProtocol <NSObject> -(NSInteger)imageWidth; @optional @property (nonatomic, copy) CGImageRef(^createImage)(NSDictionary *); @end id<CreateImageProtocol>MakeImageProvider(); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,14 @@ // // ImageProvider.h // test // // Created by Kevin Meaney on 17/10/2014. // Copyright (c) 2014 Kevin Meaney. All rights reserved. // #import <Foundation/Foundation.h> #import "CreateImageProtocol.h" @interface ImageProvider : NSObject <CreateImageProtocol> @end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ // // ImageProvider.m // test // // Created by Kevin Meaney on 17/10/2014. // Copyright (c) 2014 Kevin Meaney. All rights reserved. // #import "ImageProvider.h" @implementation ImageProvider @synthesize createImage; -(NSInteger)imageWidth { if (self.createImage) { CGImageRef myImage = self.createImage( @{ @"imagefilepath" : @"/Users/ktam/Pictures/julieanneInNZ.jpg" }); if (myImage) return CGImageGetWidth(myImage); } return -1; } @end id<CreateImageProtocol>MakeImageProvider() { return [[ImageProvider alloc] init]; } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ // // ImageProvider2.h // test // // Created by Kevin Meaney on 17/10/2014. // Copyright (c) 2014 Kevin Meaney. All rights reserved. // #import <Foundation/Foundation.h> @interface ImageProvider2 : NSObject -(NSInteger)imageWidth; @property (nonatomic, copy) CGImageRef(^createImage)(NSDictionary *); @end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ // // ImageProvider2.m // test // // Created by Kevin Meaney on 17/10/2014. // Copyright (c) 2014 Kevin Meaney. All rights reserved. // #import "ImageProvider2.h" @implementation ImageProvider2 @synthesize createImage; -(NSInteger)imageWidth { if (self.createImage) { CGImageRef myImage = self.createImage( @{ @"imagefilepath" : @"/Users/ktam/Pictures/julieanneInNZ.jpg" }); if (myImage) return CGImageGetWidth(myImage); } return -1; } @end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,43 @@ // // SupplyCreateImage.swift // test // // Created by Kevin Meaney on 17/10/2014. // Copyright (c) 2014 Kevin Meaney. All rights reserved. // import Foundation public func makeImage(dict : [ NSObject:AnyObject]! ) -> Unmanaged<CGImageRef>! { let thePath = dict["imagefilepath"]! as String let jpegURL = NSURL.fileURLWithPath(thePath, isDirectory: false) let imageSource = CGImageSourceCreateWithURL(jpegURL, nil)! let theImage = CGImageSourceCreateImageAtIndex(imageSource, 0, nil) let x = Unmanaged.passUnretained(theImage); // x.autorelease() return x } /* public func getImageWidth() -> Int { var imageProvider:AnyObject = MakeImageProvider() imageProvider.setCreateImage?(makeImage) imageProvider.imageWidth() } */ public func getImageWidth2() -> Int { let imageProvider = ImageProvider2() imageProvider.createImage = makeImage return imageProvider.imageWidth() } // public class ClassMethodWrapper : NSObject { class ClassMethodWrapper : NSObject { // public class func getImageWidth() -> Int { class func getImageWidth() -> Int { let imageProvider = ImageProvider2() imageProvider.createImage = makeImage return imageProvider.imageWidth() } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ // // main.m // test // // Created by Kevin Meaney on 17/10/2014. // Copyright (c) 2014 Kevin Meaney. All rights reserved. // #import <Foundation/Foundation.h> #import "test-Swift.h" int main(int argc, const char * argv[]) { @autoreleasepool { // NSInteger theWidth = getImageWidth2(); NSInteger theWidth = ClassMethodWrapper.getImageWidth; printf("Image width: %ld\n", theWidth); // insert code here... // NSLog(@"Hello, World!"); } return 0; }