Swiftpack.co - academypoa/AirtableKit as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by academypoa.
academypoa/AirtableKit 1.0.1
A SPM to interact with the REST Api from Airtable
⭐️ 45
🕓 1 year ago
iOS macOS
.package(url: "https://github.com/academypoa/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: 45
Last commit: 1 year ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

Stable version plus wiki
3 years ago

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