Skip to content

Instantly share code, notes, and snippets.

@dfeinzimer
Last active January 11, 2023 02:09
Show Gist options
  • Save dfeinzimer/264740f19c216a68b64ebe4180cbc675 to your computer and use it in GitHub Desktop.
Save dfeinzimer/264740f19c216a68b64ebe4180cbc675 to your computer and use it in GitHub Desktop.
SwiftUI LibraryItem bug reproducer
//
// ContentView.swift
//
// Created by David Feinzimer on 1/10/23.
//
import SwiftUI
struct ContentView: View {
var body: some View {
MyView()
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
struct MyView: View {
var action: (() -> Void)?
var body: some View {
Text("MyView")
.onTapGesture {
action?()
}
}
func setAction(_ action: @escaping () -> Void) -> MyView {
var copy = self
copy.action = action
return copy
}
}
struct LibraryContent: LibraryContentProvider {
func modifiers(base: MyView) -> [LibraryItem] {
[
LibraryItem(
base.setAction {
},
title: "MyView - Set action"
)
]
}
}
@dfeinzimer
Copy link
Author

dfeinzimer commented Jan 11, 2023

When passing an empty closure to a LibraryItem's snippet parameter, unexpected extra text is added to the file when the item is dragged in from the Xcode library.

Expected:

.setAction {
    
}

Actual:

.setAction /*@START_MENU_TOKEN@*/{
    
}/*@END_MENU_TOKEN@*/

recording

macOS 13.0.1 (22A400)
Xcode 14.1 (14B47b)

@dfeinzimer
Copy link
Author

FB11936092

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment