Swiftpack.co - developeracademypucrs/AirtableKit as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by developeracademypucrs.
developeracademypucrs/AirtableKit 1.0.1
A SPM to interact with the REST Api from Airtable
⭐️ 39
🕓 49 weeks ago
iOS macOS
.package(url: "https://github.com/developeracademypucrs/AirtableKit.git", from: "1.0.1")

AirtableKit

Supported platforms: iOS & macOS Language: Swift MIT License

Follow us Follow us

AirtableKit is a 100% Swift framework to wrap the REST API provided by Airtable. The implementation fully leverages Combine to handle asynchronous operations.

Features

  • Standard CRUD operations;
  • Operation batching;
  • API Error forwarding.

Instalation

AirtableKit only supports Swift Package Manager at the moment.

.package(url: "http://github.com/appledeveloperacademypucrs/AirtableKit.git", .upToNextMajor(from: "1.0.0"))

To install AirtableKit using Swift Package Manager look for http://github.com/appledeveloperacademypucrs/AirtableKit.git in Xcode (File/Swift Packages/Add Package Dependency...).

See Adding Package Dependencies to Your App for details.

Usage

To use AirtableKit, create an Airtable with your API Key and Base ID:


let airtable = Airtable(baseID: apiBaseId, apiKey: apiKey)

Listing records

Then, you can list items in any table in your base:


let publisher = airtable.list(tableName: tableName)

// to get only some fields
let publisher = airtable.list(tableName: tableName,
                              fields: ["name", "age", "isCool"])
        

or get an individual record, providing its ID:


let publisher = airtable.get(tableName: tableName, 
                             recordID: "YOUR_AIRTABLE_RECORD_ID")
        

Creating records

You can also create a new record:


let fields: [String: Any] = [
  "name" : "Nicolas",
  "isCool" : true
  "age" : 25,
  "updatedTime" : Date()
]

let record = Record(fields: fields)

let publisher = airtable.create(tableName: tableName, record: record)

or multiple records:


let fields: [[String: Any]] = [
  [
    "name" : "Nicolas",
    "isCool" : true
    "age" : 25,
    "updatedTime" : Date()
  ],
  [
    "name" : "Rafael",
    "isCool" : true
    "age" : 22,
    "updatedTime" : Date()
  ]
]

let records = fields.map { Record(fields: $0) }

let publisher = airtable.create(tableName: tableName, records: records)

Updating records

You can also update an existing record:

let fields: [String: Any] = [
  "name" : "Nicolas",
  "isCool" : true
  "age" : 25,
  "updatedTime" : Date()
]

let record = Record(fields: fields, id: "YOUR_AIRTABLE_RECORD_ID")

let publisher = airtable.update(tableName: tableName, record: record)

or multiple records:


let records = [
  Record(fields: [
    "name" : "Nicolas",
    "isCool" : true
    "age" : 25,
    "updatedTime" : Date()
  ], id: "YOUR_AIRTABLE_RECORD_ID_1"),
  
  Record(fields: [
    "name" : "Rafael",
    "isCool" : true
    "age" : 22,
    "updatedTime" : Date()
  ], id: "YOUR_AIRTABLE_RECORD_ID_2")
]
  
let publisher = airtable.update(tableName: tableName, records: records)

Deleting records

And finally, you can also delete an existing record:


let publisher = airtable.delete(tableName: tableName, recordID: "YOUR_AIRTABLE_RECORD_ID")

or multiple records:


let publisher = airtable.delete(tableName: tableName, recordsIDs: ["YOUR_AIRTABLE_RECORD_ID_1", "YOUR_AIRTABLE_RECORD_ID_2"])

Documentation

Full documentation of the types and methods is available on the wiki pages.

License

MIT License.

GitHub

link
Stars: 39
Last commit: 2 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

Stable version plus wiki
1 year ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics