-rw-r--r-- 706B Mar 29, 2023 · 88035de · ~1 min

Modulbank Informer

macos приложения модульбанк open source

Modulbank Informer

Recently I noticed that Modulbank, the bank I use, has a public API. Since they don’t have a macOS app, and their iOS app doesn’t run on Apple Silicon (a security restriction on their side), I built a small informer that shows the list of accounts and balances in the status bar.

The app requires macOS 13+ — I wanted to squeeze the latest features out of SwiftUI and get some practice while I was at it.

Source on GitHub: https://github.com/makoni/ModulbankInformer
Download: https://github.com/makoni/ModulbankInformer/releases

[↵] open page modulbank-informer.md
-rw-r--r-- 973B Dec 26, 2022 · BE2067B · ~1 min

Swift CouchDB client 1.2.1

swift couchdb swift package vapor open source

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 unauthorised errors now.
  • CouchDBClientError model has a description text now.

CouchDB Client on GitHub | Documentation with examples and tutorials.

[↵] open page swift-couchdb-client-1-2-1.md
-rw-r--r-- 1.1K Oct 4, 2022 · A996DD3 · ~1 min

Swift CouchDB client 1.2.0

swift couchdb swift package vapor open source

Swift CouchDB client 1.2.0

Couple months ago I started learning Apple's DocC tool that generates documentation from your source code. I've decided to use as many features as possible so I took my small lib CouchDB Client and added docs to every method including usage examples that Xcode will show in the autocomplete popup. As it often happens, during adding docs and examples I found that many things in the library 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 a couple. They're also part of the repo on GitHub.

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

CouchDB Client on GitHub | Documentation with examples and tutorials.

[↵] open page swift-couchdb-client-1-2-0.md
-rw-r--r-- 1.5K Mar 29, 2020 · C1C7EDD · ~1 min

Wrapping models in SwiftUI for Identifiable conformance

swiftui swift шпаргалки

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

Here's an example of a model:

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

An 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 an error in Xcode:

Xcode Identifiable conformance error

Sometimes you can't just change a model. It might be a data model from a third party SDK that you're using in your 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 a List"
)

let wrappedData = MyDataModelWrapper(data: testDataModel)

So the view will look like this:

struct TestView: View {
    var dataArray: [MyDataModelWrapper] 

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

Done.

[↵] open page wrapping-models-in-swiftui-for-identifiable-conformance.md
-rw-r--r-- 956B Sep 23, 2019 · B28AFA6 · ~1 min

Syntax sugar for JSON parsing in Swift

swift swift package json open source

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

var myModel: MyModel?
let decoder = JSONDecoder()

do {
    myModel = try decoder.decode(MyModel.self, from: data)
} catch {
    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 decoding just like that:

let myModel = MyModel.decodeFromData(data: data)

And the same for encoding:

let data = MyModel.encode(fromEncodable: myModel)

All you need is just to add protocol conformance:

extension MyModel: Parseable {
    typealias ParseableType = Self
}

It's available on GitHub as a Swift Package: https://github.com/makoni/parsable

[↵] open page syntax-sugar-for-json-parsing-in-swift.md
makoni@arm1:~/blog$ cd ../page-6/ // ← previous cd ./page-8/ // more posts →