GithubHelp home page GithubHelp logo

Comments (1)

rafaelruwer avatar rafaelruwer commented on July 2, 2024

Hi @jeadev!

Sorry for the long delay. If this is still relevant to you, I created a small example of how you can parse the records from a table in your Airtable base.

The package uses Combine as its interface for returning the status of operations performed (create, delete) or the data requested (list, get). Given that Combine is a new framework, let's say you're using closures instead of Combine on your application.

I'm considering you have a class to encapsulate communication with Airtable. You can do something like the following:

import Combine
import AirtableKit

class Service {
    
    private let airtable = Airtable(baseID: "<your base id>", apiKey: "<your API key>")
    private var subscriptions: [AnyCancellable] = []
    
    func listStudents(completion: @escaping (Result<[[String]], Error>) -> Void) {
        airtable.list(tableName: "<your table name>")
            .sink { completionEvent in
                switch completionEvent {
                case .finished:
                    // you can ignore this
                    print("successfully finished")
                case .failure(let error):
                    print("got error \(error)")
                    completion(.failure(error))
                }
            } receiveValue: { records in
                print("records \(records)")
                
                let content = records.map { record -> [String] in
                    // map your record/row here
                    
                    var result = [String]()
                    
                    if let name = record.fields["Name"] as? String {
                        result.append(name)
                    }
                    
                    if let logo = record.attachments["Picture"]?.first {
                        let logoUrl = logo.url.absoluteString
                        let logoSize = logo.metadata["size"] as? Int ?? 0
                        
                        result.append(logoUrl)
                        result.append("\(logoSize)")
                    }
                    
                    return result
                }
                
                completion(.success(content))
                
            }
            .store(in: &subscriptions)
    }
}

Now to use it on your app:

let service = Service()

func getDataFromAirtable() {
    service.listStudents { result in
        switch result {
        case .success(let rows):
            // do something with rows
            print("result: success \(rows)")
        case .failure(let error):
            // handle this as you wish
            print("result: error \(error)")
        }
    }
}

I haven't written SpriteKit code for some time now, but I think you can use this as a starting point to implement what you need.

I'll close this for now, but feel free to comment and I'll see how I can help.

from airtablekit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.