CloudInfo SDK in Swift project

Is there a way to use the Obj-C SDK in a Swift file? I tried adding a cloud SDK to my project. I found a way to add libcloudinary.a to my Framework projects, but it doesn't work.

UPDATE : Cloudinary just released new Swift SDKs: https://github.com/cloudinary/cloudinary_ios (Swift 3 and Swift 2.3 on separate brunches)

+4
source share
4 answers

Yes, you can.

-, xcode- , . , Swift docs.

#ifndef Fun_Bridging_Header_h
#define Fun_Bridging_Header_h

#import "Cloudinary.h"

#endif

, API objective-c Swift, API (CLUploader).

, , factory objective-c

(CloudinaryFactory.h)

#ifndef Fun_Wrappy_h
#define Fun_Wrappy_h
#import "Cloudinary.h"

@interface CloudinaryFactory : NSObject  
+ (CLUploader*)create:(CLCloudinary*)cloudinary delegate:(id <CLUploaderDelegate> )delegate;
@end

#endif 

(CloudinaryFactory.m):

#import "CloudinaryFactory.h"

@implementation CloudinaryFactory  

+ (CLUploader*)create:(CLCloudinary*)cloudinary delegate:(id <CLUploaderDelegate> )delegate
{
    return [[CLUploader alloc] init:cloudinary delegate:delegate];
}

@end

#ifndef Fun_Bridging_Header_h
#define Fun_Bridging_Header_h

#import "CloudinaryFactory.h"

#endif

, :

 var image:UIImage? //todo: i'm assuming you would set this somewhere
 @IBAction func uploadGarment(sender: AnyObject) {
    let clouder = CLCloudinary(url: "cloudinary://your:cloudinary@url")

    let forUpload = UIImagePNGRepresentation(image) as NSData
    let uploader = CloudinaryFactory.create(clouder, delegate: self)

    uploader.upload(forUpload, options: ["public_id":"testo"])   

}

, ! ,

+5

:

  • Podfile: pod "Cloudinary"
  • pod install, , .
  • Obj-C (http://cl.ly/image/272V1Z2Q3g0e), , "" Objective-C/li >
  • #import "Cloudinary/Cloudinary.h"
  • Cloudinary API. :

    let cloudinary_url = "cloudinary://API_KEY:API_SECRET@CLOUD_NAME"
    var uploader:CLUploader = CLUploader(cloudinary, delegate: self)
    uploader.upload(UIImageJPEGRepresentation(new_image, 0.8), options: ["format":"jpg"], withCompletion: { ([NSObject : AnyObject]!, errorResult:String!, code:Int, context:AnyObject!) -> Void in
    
    }, andProgress: { (p1:Int, p2:Int, p3:Int, p4:AnyObject!) -> Void in
    
    })
    
+6

. .h .

: 1 : xyz-Bridging-header.h

Import CloudMan.h file into header file with bridge

#import "Cloudinary.h"

2 Step: ViewController.swift

Class viewController : UIViewController {
      cloudinary: CLCloudinary = CLCloudinary()
      override func viewDidLoad() {
            super.viewDidLoad()
            // Cloudinary Setup
            cloudinary.config().setValue("xxxxxxxx", forKey: "cloud_name")
            cloudinary.config().setValue("xxxxxxxx", forKey: "api_key")
            cloudinary.config().setValue("xxxxxxxx", forKey: "api_secret")
      }
}

Configuring Cloudinary . now you can use.

+1
source

All Articles