swi

SwiftAirtable

An unofficial Swift interface to Airtable's REST API

Showing:

Popularity

Downloads/wk

0

GitHub Stars

45

Maintenance

Last Commit

1yr ago

Contributors

1

Package

Dependencies

0

License

MIT

Categories

Readme

Update

For a more modern implementation, see AirtableKit

SwiftAirtable

Alt Text

Description

An unofficial Swift interface to Airtable's REST API

Usage

In order to make use of the Framework, simply create a strucuture

struct AirtablePerson {
    // The airtable object id
    var id: String = ""
    var name: String = ""
}

and make it adopt the AirtableObject protocol

extension AirtablePerson: AirtableObject {
    static var fieldKeys: [(fieldName: String, fieldType: AirtableTableSchemaFieldKey.KeyType)] {
        var fields = [(fieldName: String, fieldType: AirtableTableSchemaFieldKey.KeyType)]()
        fields.append((fieldName: AirtableField.name.rawValue, fieldType: .singleLineText))
        return fields
    }
    
    func value(forKey key: AirtableTableSchemaFieldKey) -> AirtableValue? {
        switch key {
        case AirtableTableSchemaFieldKey(fieldName: AirtableField.name.rawValue, fieldType: .singleLineText): return self.name
        default: return nil
        }
    }
    
    init(withId id: String, populatedTableSchemaKeys tableSchemaKeys: [AirtableTableSchemaFieldKey : AirtableValue]) {
        self.id = id
        tableSchemaKeys.forEach { element in
            switch element.key {
            case AirtableTableSchemaFieldKey(fieldName: AirtableField.name.rawValue, fieldType: .singleLineText): self.name = element.value.stringValue
            default: break
            }
        }
    }
}

Finally create an Airtable to perform the operations

let airtable = Airtable(apiKey: apiKey, apiBaseUrl: apiBaseUrl, schema: AirtablePerson.schema)

You can perform all standard CRUD operations

Create

airtable.createObject(with: object, inTable: table) { object: AirtablePerson, error: Error? in
    if let error = error {
        // Error Code
    } else {
        // Success Code
    }
}

Retrieve

airtable.fetchAll(table: table) { (objects: [AirtablePerson], error: Error?) in
    if let error = error {
        // Error Code
    } else {
        // Success Code
    }
}

Update

airtable.updateObject(with: object, inTable: table) { object: AirtablePerson?, error: Error? in
    if let error = error {
        // Error Code
    } else {
        // Success Code
    }
}

Delete

airtable.deleteObject(with: object, inTable: table) { sucess, error in
    if let error = error {
        // Error Code
    } else {
        // Success Code
    }
}

Example

To run the example project, clone the repo, and run pod install from the Example directory first. You'll need to provide your API Key and Base URL.

Installation

SwiftAirtable is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'SwiftAirtable'

Author

Nicolas Nascimento, npn.adsl@gmail.com

Sourcery

An stencil file is provided in the repo that allows you generate code for the AirtableObject protocol using Sourcery (https://github.com/krzysztofzablocki/Sourcery)

License

SwiftAirtable is available under the MIT license. See the LICENSE file for more info.

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100