KMM/Sqldelight: last_insert_rowid() returns zero on iOS

With iOS's SqliteDriver (unlike with Android's) the same connection isn't reused if you call last_insert_rowid() after an insert, meaning last_insert_rowid() will return zero, and so to force connection reuse you can use transactionWithResult on your sqldelight database connection.

public suspend fun insert(something: Text): Long {
  return db.transactionWithResult {
    db.insert(
      id = null,
      something = something
    )
    db.getInsertedID().executeAsOne()
  }
}

getInsertedID resolves to the SQL getInsertedID: SELECT last_insert_rowid(); in your sq file in this case.

kotlin kmm ios

Swift/KMM: Convert a Int64 to a KotlinLong

If you're passing Int64s into Kotlin lamdas, they don't get automatically converted into KotlinLongs, at least in 2022. You can create a Swift extension method that does this.

extension Int64 {
    func toLong() -> KotlinLong {
        return KotlinLong(value: self)
    }
}

And then do someInt64.toLong() as you pass the parameters into the Kotlin lambda.

swift kmm kotlin

SwiftUI: Make a rounded rectangle with a point (speech bubble)

We'll create a rounded rectangle with a triangular point that is at the centre left.

Create a background on your View that has a ZStack with centre leading alignment. The ZStack will have three views.

The first view is a RoundedRectangle with a stroke and a white background.

The second view is a Rectangle with a 1px stroke that's rotated 45 degrees and offset slightly to the left to create the point.

The final Rectangle is the same as the second, without the stroke but with a white fill, and offset 1 further to the right to erase the right-hand border of the second Rectangle.

ZStack(alignment: .topLeading) {
  Text("Popover")
      .font(.system(size: 30.0))
      .padding(.all, 5)
}
.background {
  ZStack(alignment: .init(horizontal: .leading, vertical: .center)) {
    RoundedRectangle(cornerRadius: 10)
        .stroke(Color.gray, lineWidth: 1)
        .overlay {
            RoundedRectangle(cornerRadius: 10)
                .fill(Color.white)
        }
    Rectangle() // the point
        .strokeBorder(.gray, lineWidth: 1.0)
        .background(.white)
        .frame(width: 20, height: 20)
        .rotationEffect(.degrees(45.0))
        .offset(x: -10, y: 0)
    Rectangle() // erasing the point's right border
        .fill(.white)
        .frame(width: 20, height: 20)
        .rotationEffect(.degrees(45.0))
        .offset(x: -9, y: 0)
}
swiftui

SwiftUI: Force hide the keyboard

Define this extension method on UIApplication:

extension UIApplication {
  func endEditing() {
    sendAction(
      #selector(UIResponder.resignFirstResponder), 
      to: nil, 
      from: nil, 
      for: nil
    )
  }
}

And then call it using UIApplication.shared.endEditing()

swiftui ios
Page 1 of 216 โ†’
vimscript tut
plpgsql tut
unix  
vim 
ios 
css 
java  



I'm no longer visiting the Reddit tabloid. It's anger-inducing and divisive
I'm writing small thoughts here