There is a yet another new new SDK in town! This time around, it's the iOS/macOS SDK. Written completely in Objective-C, yet supporting Objective-C and Swift - this SDK is set to be the new standard for iOS and macOS. With the release of version 1.0.0, it supplies basic Transloadit functionality while utilizing tus style uploads. Further updates are also already in the works to fully support all of what Transloadit has to offer.

The Apple logo, with a silhouette of Steve Jobs' head on the right side.

It's very easy to start using Transloadit for Objective-C and Swift, using CocoaPods. Here are a few simple steps you'll have to take:

  1. Simply add 'Transloadit' to your Podfile
  2. Run pod install
  3. Add your Transloadit keys to your Info.plist file
	<key>TRANSLOADIT_KEY</key>
	<string>YOUR_TRANSLOADIT_KEY</string>
	<key>TRANSLOADIT_SECRET</key>
	<string>YOUR_TRANSLOADIT_SECRET</string>
  1. Be sure to import Transloadit on the pages where you need it

Objective-C:

#import "Transloadit.h"

Swift:

// Due to Swift being unable to handle non-modular headers, TransloaditKit currently requires a dependency while running on Swift
import Arcane
import TransloaditKit

And that's it, you're all set!

A quick example of creating an Assembly

First, you'll have to create an Assembly Step:

Objective-C:

// Assembly Steps
NSMutableArray<Step *> *steps = [[NSMutableArray alloc] init]; // An array to hold the Steps
Step *step1 = [[Step alloc] initWithKey:@"encode"]; // Create a Step object
[step1 setValue:@"/image/resize" forOption:@"robot"]; // Add the details
[steps addObject:step1]; // Add the Step to the array

Swift:

// Assembly Steps
var AssemblySteps: Array = Array<Step>() // An array to hold the Steps
var Step1 = Step (key: "encode") // Create a Step object
Step1?.setValue("/image/resize", forOption: "robot") // Add the details
AssemblySteps.append(with: Step1) // Add the Step to the array

And then we create the Assembly itself

Objective-C:

// We then create an Assembly object with the Steps and files
Assembly *TestAssemblyWithSteps = [[Assembly alloc] initWithSteps:steps andNumberOfFiles:1];
[TestAssemblyWithSteps addFile:fileUrl]; // Add the file

[transloadit createAssembly:TestAssemblyWithSteps]; // Create the Assembly

Swift:

// We then create an Assembly object with the Steps and files
var TestAssembly: Assembly = Assembly(steps: AssemblySteps, andNumberOfFiles: 1)
TestAssembly.addFile(fileURL) // Add the file

Transloadit.createAssembly(TestAssembly) // Create the Assembly

And now for our blocks!

Objective-C:

// Blocks
// This block fires after the creation of your Assembly
transloadit.assemblyCompletionBlock = ^(NSDictionary* completionDictionary){
  [TestAssemblyWithSteps setUrlString:[completionDictionary valueForKey:@"assembly_ssl_url"]]; // Set the URL for your Assembly so the file knows where to go
  [transloadit invokeAssembly:TestAssemblyWithSteps]; // Starts the Assembly
  [transloadit checkAssembly:TestAssemblyWithSteps]; // Ping the status of your Assembly
};

// Fires after your Assembly has completed
transloadit.assemblyStatusBlock = ^(NSDictionary* completionDictionary){
  NSLog(@"%@", [completionDictionary description]);
};

Swift:

Transloadit.assemblyCompletionBlock = {(_ completionDictionary: [AnyHashable: Any]) -> Void in
/*Invoking the Assembly inside the completion block is NOT required, however, for the sake of a small UI it is advisable. In order to do so, we will need to add the URL to the Assembly object so that when we do invoke it, it knows where to go.*/
  TestAssemblyWithSteps.urlString = completionDictionary.value(forKey: "assembly_ssl_url")
  Transloadit.invokeAssembly(TestAssembly) // Starts the Assembly
  Transloadit.checkAssembly(TestAssembly)
}

// Fires after your Assembly has completed
transloadit.assemblyStatusBlock = {(_ completionDictionary: [AnyHashable: Any]) -> Void in
  print("\(completionDictionary.description)")
}

And that's it for basic usage! As always, we encourage the community to help us improve, grow and expand the experience of our SDKs.

You can find more information over at our docs and the GitHub Page.