Very interesting thread!
Anyways, supposed to have a Swift sources SDK that relies on let’s say Http stack (let’s say Alamofire - https://github.com/Alamofire/Alamofire), the first issue I see here is that this relies on Cocoa HTTP stack (Foundation’s NSURL stuff).
The same we can have with libraries like Crypto, that relies on the platform itself, let’s take this basic example here
import Foundation
import CryptoSwift
extension String {
func aesEncrypt(key: String, iv: String) throws -> String{
let data = self.dataUsingEncoding(NSUTF8StringEncoding)
let enc = try AES(key: key, iv: iv, blockMode:.CBC).encrypt(data!.arrayOfBytes(), padding: PKCS7())
let encData = NSData(bytes: enc, length: Int(enc.count))
let base64String: String = encData.base64EncodedStringWithOptions(NSDataBase64EncodingOptions(rawValue: 0));
let result = String(base64String)
return result
}
func aesDecrypt(key: String, iv: String) throws -> String {
let data = NSData(base64EncodedString: self, options: NSDataBase64DecodingOptions(rawValue: 0))
let dec = try AES(key: key, iv: iv, blockMode:.CBC).decrypt(data!.arrayOfBytes(), padding: PKCS7())
let decData = NSData(bytes: dec, length: Int(dec.count))
let result = NSString(data: decData, encoding: NSUTF8StringEncoding)
return String(result!)
}
}
(from: https://gist.github.com/yutelin/f4f66e0c78474db1de51)
Here you need NSData
(so the binary data handlers) and its encoding/decoding counterparts:
base64EncodedStringWithOptions
, NSDataBase64DecodingOptions
Also it relies on a cross platform AES crypt/decrypt lib - https://github.com/Pakhee/Cross-platform-AES-encryption.
Another examples could be done with XML / JSON Parsers made from the scratch (not relying on Cocoa libraries, but ISA only, etc.), they still need the Cocoa Foundation.
My last example was to have a Promise-like in Silver, that can be implemented using the language itself (pure Swift) for most of its patterns, and it’s quite like ready.