If you’re building macOS or iOS apps that need to access Microsoft Azure Storage—read on.

Microsoft deprecated the Objective-C based azure-storage client library a while back. There is a newer Azure SDK for iOS SDK but has not yet included a Swift-based API for storage access. There are Azure REST APIs, but they add a lot of extra code over the client library APIs.

If you prefer to develop using client library methods over REST, check out my Swift package—AzureStorageSwift. There is also AzureBlobCLI—a simple application showing how to use the AzureStorageSwift package.

Usage

To use AzureStorageSwift, simply point Swift PM at https://github.com/oliwonders/AzureStorageSwift.git. Once it’s in your project, you can call the APIs like this:


import AzureStorageSwift

let sasUrl = "https://yourstorageaccount.blob.core.windows.net/containername?sv=..."

let container = try AZSCloudBlobContainer(url: URL(string: sasUrl))

// List blobs in the container
container.listBlobsSegmented(
    with: nil,
    prefix: nil,
    useFlatBlobListing: true,
    blobListingDetails: AZSBlobListingDetails(),
    maxResults: 50
) { (error, results) in
    if let error = error {
        print("Error listing blobs:\(error.localizedDescription)")
        return
   }

    guard let blobs = results?.blobs as? [AZSCloudBlob] else {
    print("No blobs found or unable to cast results")
            return
        }

    print("Found \(blobs.count) blobs:")
    for blob in blobs {
        print("- \(blob.blobName ?? "Unknown")")
    }
}

Hope you find this useful!

You can reach me at david@oliwonders.com.