Home > OS >  Trying to figure out Swift Clients for Thrift
Trying to figure out Swift Clients for Thrift

Time:07-14

I want to utilize thrift from within my new MacOS App. The app is working fine so far as a menubar app.. it takes in a string and lets you save it to memory somewhere... if you click on the clipboard button it saves your string to clipboard.

enter image description here

What I do not understand is.. if I've generated some Swift Client code via the

thrift --gen swift <name_of_thrift_file.thrift>

I get two .swift files, as expected.. AND instructions from the github to rig up the Client object.. here's my Client Object so far.. but I am seeing a error already with the example code. I want to add a status button to the menubar app (anywhere) .. which calls my thrift server for a ping() and goes green once response looks good.

enter image description here

Targeting : Mac OS 12.x

Thrift Version : v0.16.0

XCode Version : 13.x

CodePudding user response:

happily I hand rolled the library (Thrift) into my project.. for some reason I think the package mangement didn't work.. once added it was a breeze to generate my .thrift files

thrift --gen swift <my_thrift_service>.thrift

once I buttoned all that together in XCode.. the last part was getting a client that worked.. the example in git was showing an error but I got past it with this

AWSBotor3ThriftClient.swift

import Foundation


class AWSBoto3ThriftClient {
    
    var boto3_thrift_client :aws_boto3_accessorClient?
    var server_status :Int32
    
    init() {
        do {
            let transport = try TSocketTransport(hostname: "localhost", port: 9090)
            let proto = TBinaryProtocol(on: transport)
            let client = aws_boto3_accessorClient(inoutProtocol: proto)
            
            self.boto3_thrift_client = client
            self.server_status = try self.boto3_thrift_client!.ping()
        } catch {
            print("init had a boo boo :(")
            self.server_status = 333
            self.boto3_thrift_client = nil
        }
        print(self.server_status)
    }
}

S3SyncAppApp.swift

import SwiftUI


@main
struct S3SyncAppApp: App {
    @NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
    @State var currentNumber: String = "1"
    
    var my_little_client: AWSBoto3ThriftClient = AWSBoto3ThriftClient()
    
    var body: some Scene {
        WindowGroup {
             ContentView()
        }
    }    
}
  • Related