-rw-r--r-- 1.2K Apr 8, 2024 · 08DA6BF · ~1 min

Swift CouchDB client 1.4.0

swift couchdb swift package vapor open source

Swift CouchDB client

A new version of CouchDB Client has been released:

  • The library migrated from HTTPClient.Response to HTTPClientResponse, which is similar to HTTPClient.Response but used for the Swift Concurrency API. It also migrated from HTTPClient.Body to HTTPClientRequest.Body. These changes impact the get and find methods. Old methods are marked as deprecated, please refer to the documentation for the updated methods.
  • The minimum Swift version is now 5.8.
  • The CouchDBRepresentable protocol is now marked as Codable.
  • Additionally, a new data model called RowsResponse has been added. It accepts a generic CouchDBRepresentable type, making it easier to retrieve rows from a database. For example:
    let decodeResponse = try JSONDecoder().decode(RowsResponse<MyApp>.self, from: data)
  • Lastly, there have been small improvements in the documentation and tutorials.

CouchDB Client on GitHub | Documentation with examples and tutorials.

[↵] open page swift-couchdb-client-1-4-0.md
-rw-r--r-- 1.1K Apr 4, 2024 · 0427246 · ~1 min

A middleware for Vapor 4 routing to trim a slash in url path

vapor code snippets шпаргалки swift server side swift

It’s a common thing for a website or a backend to allow URLs like mySite.com/webpage and mySite.Com/webpage/ for the same page. These pages are different URLs for a search engine. If you want to avoid duplicates, you can add a simple middleware to trim the ending slash and redirect a user.

Here’s an example code for such a middleware class for Vapor 4:

final class TrimSlashInPathMiddleware: Middleware {
    func respond(to request: Request, chainingTo next: Responder) -> EventLoopFuture<Response> {
        if request.url.path.count > 1, request.url.path.hasSuffix("/") {
            let newPath = String(request.url.path.trimmingSuffix(while: { $0 == "/" }))
            let response = request.redirect(to: newPath, redirectType: .permanent)
            return request.eventLoop.makeSucceededFuture(response)
        }
        return next.respond(to: request)
    }
}

Just add it to configure.swift file:

import Vapor

public func configure(_ app: Application) throws {
    app.middleware.use(TrimSlashInPathMiddleware())

    app.http.server.configuration.port = 8081

    try routes(app)
}

Works with Vapor 4.92.5.

[↵] open page a-middleware-for-vapor4-to-trim-a-slash-in-url-path.md
-rw-r--r-- 506B Apr 3, 2024 · BC252B6 · ~1 min

Modulbank informer 1.3

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

Modulbank Informer 1.3

Released a small update for Modulbank Informer. Updated the status bar icon (now more recognizable) and added a checkbox to hide accounts with zero balance. Plus, some minor refactoring.

Source code on GitHub: https://github.com/makoni/ModulbankInformer
You can download it here: https://github.com/makoni/ModulbankInformer/releases

[↵] open page modulbank-informer-1-3.md
-rw-r--r-- 2.4K Mar 30, 2024 · E0344BE · ~2 min

How to get selected text inside of TextEditor in SwiftUI on macOS

swiftui macos

How to get selected text inside of TextEditor in SwiftUI on macOS

TextEditor in SwiftUI still doesn’t have any API to get user selection. But since it’s using NSTextView internally we can subscribe to its notifications.

Here’s an example of getting a substring from user selection:

[↵] open page how-to-get-selected-text-inside-of-texteditor-in-swiftui-on-macos.md
-rw-r--r-- 836B Mar 29, 2024 · EA452FF · ~1 min

Swift CouchDB client 1.3.2

swift couchdb swift package vapor open source

Swift CouchDB client

Recently, there have been a couple of new releases for my Swift CouchDB library. Here are the recent changes:

  • dateDecodingStrategy and dateEncodingStrategy can now be passed as parameters for get, update and insert methods.
  • Added a check to handle expired authentication cookies.
  • Comparing the set-cookie header in the response as lowercased.
  • Introduced new methods to utilize the _find API, allowing you to find documents using a declarative JSON querying syntax
  • Fixed an issue where the update method didn’t use dateEncodingStrategy parameter.

CouchDB Client on GitHub | Documentation with examples and tutorials.

[↵] open page swift-couchdb-client-1-3-2.md
-rw-r--r-- 1.2K Oct 10, 2023 · d68e288 · ~1 min

AppMetric 1.8

macos приложения appmetric appmetrica

AppMetric 1.8

I’ve updated AppMetric for macOS — a client for Yandex’s AppMetrica service. The previous version, sadly, stopped working when they changed their response format.

From what I’ve been able to figure out, I was using something undocumented in their response. And judging by the current API responses, that was the number of crashes. Unfortunately, I had to remove it and replace it with the number of devices.

Since I finally got my hands on it, I decided to bring it up to date. Reworked everything in SwiftUI, but had to wrap the popup itself in good old NSPopover, because MenuBarExtra from SwiftUI is far too limited. Maybe I’ll get around to writing a separate post about it. While I was at it, I migrated everything to Swift Concurrency and SF Symbols. The catch is that it now requires macOS 13+, but I assume the people who find it useful keep their Macs up to date too. And, of course, finally — native Apple Silicon support.

The update went through review today and is available for download. In the future I’d like to add per-day/per-week charts.

Download

[↵] open page appmetric-1-8.md
makoni@arm1:~/blog$ cd ../page-5/ // ← previous cd ./page-7/ // more posts →