Last active
July 27, 2024 04:03
-
-
Save benigumocom/eeb467e92f65d8509041152227b1606c to your computer and use it in GitHub Desktop.
【SwiftUI + SwiftData】List のアイテムの Preview 👉 https://android.benigumo.com/20240725/preview-one-item/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
import SwiftData | |
struct PreviewOneModelView<Model: PersistentModel, Content: View>: View { | |
var content: (Model) -> Content | |
@Query private var models: [Model] | |
var body: some View { | |
content(models.first!) | |
} | |
} | |
/* ex. | |
#Preview { | |
PreviewOneModelView { item in | |
ItemView(item: item) | |
} | |
.modelContainer(for: Item.self, inMemory: false) | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment