Arm1.ru

Модульбанк информер

Недавно увидел, что у Модульбанка, которым я пользуюсь, есть публичный API. Поскольку у них для macOS нет приложения, а приложение для iOS не работает на Apple Silicon в целях безопасности, я сделал небольшой информер, который показывает в статус баре список счетов и баланс.

Приложение macOS 13+, т.к. хотелось выжать из SwiftUI всё самое актуальное, заодно попрактиковаться.

Исходный код на GitHub: https://github.com/makoni/ModulbankInformer
Скачать можно тут: https://github.com/makoni/ModulbankInformer/releases

comment comments

Swift CouchDB client 1.2.1

Just a small update for Swift CouchDB client lib with couple new methods that I needed by myself:

  • Added a new method to create a database [docs].
  • Added a new method to delete a database [docs].
  • Added a new method to check if a database exists [docs].
  • Every request handles unauthorized error now.
  • CouchDBClientError model has a description text now.

CouchDB Client on GitHub | Documentation with examples and tutorials.

comment comments

Swift CouchDB client 1.2.0

Couple months ago I've started learning Apple's DocC tool that generates documentation from your source code. I've decided to use as many features as possible so took my small lib CouchDB Client and added docs to every method including usage examples that Xcode will show in autocompletion popup. As it often happens, during adding docs and examples I found that many things in the lib can be done in a much better way. So I've updated existing methods and added some more that can take a doc as a param and use generic types.

Next step was tutorials. Apple allows devs to create exactly the same tutorials as they have for SwiftUI on their own website. So I've added couple. They're also part of the repo on GitHub.

Pretty sure that I've spent more time on the docs than on the lib itself but I hope it's worth it.

CouchDB Client on GitHub | Documentation with examples and tutorials.

comment comments

Password generation using Security Framework on iOS and macOS

Couple lines of code to generate a 15 characters length password (just like in Safari):

import Security
 
let pass = SecCreateSharedWebCredentialPassword() as String?
print(pass ?? "oops")

comment comments

Swift CouchDB client 1.0.0

Finished new version of Swift CouchDB client. Now it's using only async-http-client as dependency to make http/https requests. Can be used with Vapor 4. 

Available on Github: https://github.com/makoni/couchdb-vapor

comment comments

Wrapping models in SwiftUI for Identifiable conformance

Using array of models in List view in SwiftUI requires conformance to Identifiable protocol.

Here's an example of model:

struct MyDataModel {
    let title: String
    let message: String
}

Example of SwiftUI view that you want to display a list:

struct TestView: View {
    var dataArray: [MyDataModel]

    var body: some View {
        List(dataArray) { data in
            VStack {
                Text(data.title)
                Text(data.message)
            }
        }
    }
}

Using MyDataModel in List will show you error in Xcode:

Sometimes you can't just change the model. It might be a data model from third part SDK that you're using in you app.

But you can create a wrapper for this struct to confirm Identifiable protocol:

struct MyDataModelWrapper: Identifiable {
    var id = UUID()
    var data: MyDataModel
}
let testDataModel = MyDataModel(title: "Title 1", message: "I wanna be used inside of List")
let wrappedData = MyDataModelWrapper(data: testDataModel)

So view will look like this:

struct TestView: View {
    var dataArray: [MyDataModelWrapper]

    var body: some View {
        List(dataArray) { wrappedData in
            VStack {
                Text(wrappedData.data.title)
                Text(wrappedData.data.message)
            }
        }
    }
}

Done.

comment comments
local_offer swiftui swift

Syntax sugar for JSON parsing in Swift

JSON parsing and encoding became easy after adding Codable protocol. But during coding I wanted to have something shorter and more elegant than Do-Catch statement that looks like this:

var myModel: MyModel?
do {
  myModel = try decoder.decode(MyModel.self, from: data)
} catch (let error) {
  print(error.localizedDescription)
}

Or like this:

let myModel: MyModel? = try? decoder.decode(MyModel.self, from: data)

So I wrote a protocol with default implementation that allows to do just that:

let myModel = MyModel.decodeFromData(data: data)

And the same for encoding:

let data = MyModel.encode(fromEncodable: myModel)

All you need is just protocol conformance:

extension MyModel: Parseable {
  typealias ParseableType = Self
}

It's available on GitHub and might be used with Swift Package Manager: https://github.com/makoni/parsable

comment comments