Skip to content

Instantly share code, notes, and snippets.

View ralfebert's full-sized avatar

Ralf Ebert ralfebert

View GitHub Profile

FB9624610: Formatting Swift code using an external tool like swiftformat on Save

I am using the splendid command-line tool swiftformat (https://github.com/nicklockwood/SwiftFormat) to format my Swift code.

For my, the perfect integration point for this tool would be on Save in Xcode. In that way the formatting would not interrupt my editing, but I can see/check the changes done by the formatter, but never forget to format a file after editing.

I'd like to suggest a configuration option for Xcode that allows to configure it in such a way that, when I press save (cmd S) it saves the file and then runs a command line utility and reloads the file - or a capability for an Xcode source code editor extension to do such an operation.

One alternative could be to do it at build time which is possible to configure currently using a Build phase (https://github.com/nicklockwood/SwiftFormat#xcode-build-phase), but unfortunately, with this setup one loses all the undo history in Xcode.

import MapKit
extension CLLocationCoordinate2D {
/// Returns the distance between two coordinates in meters.
func distance(to: CLLocationCoordinate2D) -> CLLocationDistance {
MKMapPoint(self).distance(to: MKMapPoint(to))
}
}
import SwiftUI
import BottomSheet
struct ContentView: View {
@State private var bottomSheetPresented = true
var body: some View {
Color.yellow
.ignoresSafeArea()
.bottomSheet(isPresented: $bottomSheetPresented) {
{
"images" : [
{
"filename" : "icon_20pt@2x.png",
"idiom" : "iphone",
"scale" : "2x",
"size" : "20x20"
},
{
"filename" : "icon_20pt@3x.png",
import Foundation
import CoreData
extension NSPersistentContainer {
typealias ErrorHandler = (NSError) -> Void
convenience init(defaultContainerWithName name : String, inMemory : Bool = false, errorHandler : ErrorHandler? = nil) {
self.init(name: name)
import Foundation
import SwiftUI
struct IndexedCollection<Base: RandomAccessCollection>: RandomAccessCollection {
typealias Index = Base.Index
typealias Element = (index: Index, element: Base.Element)
let base: Base
var startIndex: Index { self.base.startIndex }
var endIndex: Index { self.base.endIndex }
func index(after i: Index) -> Index {
@ralfebert
ralfebert / .bashrc
Created August 9, 2010 19:16
git settings
# Prompt (Debian)
source /usr/local/bin/git-completion.sh
# Prompt (OS X + homebrew)
source /usr/local/etc/bash_completion.d/git-completion.bash
PS1="\[\033[31;38m\]\w\[\033[1;31m\]\$(__git_ps1)\[\033[00m\] "
export GIT_PS1_SHOWDIRTYSTATE=1

FB9165511: Swift compiler accepts an invalid circular reference in some conditions

The following code example doesn't compile because of the circular reference. Except if you uncomment the line that uses the weak self. It's still an invalid circular reference, but all of a sudden the compiler accepts it. Happens with Xcode 12.5 and 13 Beta 1.

class Flupp {
    init() {
        print("Flupp!")
    }
 deinit {
import CoreHaptics
import SwiftUI
enum FeedbackType {
case selection, success, error
}
class Haptics {
@AppStorage("HaptikFeedbackEnabled") var haptikFeedbackEnabled = true