Problem Resolved!
Cause
WidgetConfigurationIntent in other SwiftPackage is not loaded correctly
How to Fix
Move to Main(Widget) Target
Post
Replies
Boosts
Views
Activity
struct TitleEditView: View {
@Environment(Book.self) private var book
var body: some View {
@Bindable var book = book
TextField("Title", text: $book.title)
}
}
I found this from Bindable Document
https://developer.apple.com/documentation/swiftui/bindable
thanks @macrojd
https://developer.apple.com/documentation/swiftui/widgetconfiguration/disfavoredlocations(_:for:)?changes=latest_major&language=objc
This code has good performance. But it is not cleaner than @EnvironmentObject
struct View2: View {
@Environment(View1Model.self) var viewModel
var body: some View {
TextField("Text", text: Binding(get: {
viewModel.text
}, set: { newValue in
viewModel.text = newValue
}))
}
}
At the moment, @Environment can't use for Binding
I don't know whether it's a bug or not
https://developer.apple.com/forums/thread/732658
I use RegexComponentBuilder.buildPartialBlock but different result
let words = ["@apple", "#swift"]
func getRegex() -> some RegexComponent {
var regex = RegexComponentBuilder.buildPartialBlock(first: Regex { words.first! } )
for word in words[1...] {
regex = RegexComponentBuilder.buildPartialBlock(accumulated: regex, next: Regex { word })
}
return ChoiceOf { regex }
}
let regex1 = getRegex()
let regex2 = Regex {
ChoiceOf {
"@swift"
"#swift"
}
}
let string = "aaa @swift #swift aaa"
for match in string.matches(of: regex1) {
print(String(string[match.range]))
} // print ""
for match in string.matches(of: regex2) {
print(String(string[match.range]))
} // @swift #swift
This problem is not happened when run again.
This bug is fixed in iOS 16 beta 5.
I fixed with navigationDestination(isPresented:)
import SwiftUI
struct ContentView: View {
@State var isPresentedDetailView = false
@State var isPresentedImageView = false
var body: some View {
NavigationStack {
List {
HStack {
Text("Name")
.onTapGesture {
isPresentedDetailView.toggle()
}
Image(systemName: "person")
.onTapGesture {
isPresentedImageView.toggle()
}
}
}
.navigationDestination(isPresented: $isPresentedImageView) {
Image(systemName: "person")
}
.navigationDestination(isPresented: $isPresentedDetailView) {
Text("Detail View")
}
}
}
}
I found resolution. user NavigationPath
struct TimelineView: View {
@State var path = NavigationPath()
let tweets: [Tweet] = tweets
let users: [User] = users
var body: some View {
NavigationStack(path: $path) {
List(tweets) { tweet in
let user = users.first { $0.id == tweet.userID }!
HStack {
Image(systemName: "person")
.onTapGesture {
path.append(user)
}
VStack {
Text("@\(user.name)")
Text(tweet.text)
}
Spacer()
}
.swipeActions(edge: .leading) {
Button("Like") { }
}
.contentShape(Rectangle())
.onTapGesture {
path.append(tweet)
}
}
.navigationDestination(for: Tweet.self) { tweet in
TweetDetailView(tweet: tweet)
}
.navigationDestination(for: User.self) { user in
UserDetailView(user: user)
}
}
}
}
same in Beta 5.
This problem fixed in iOS 16 beta 5. thanks
https://github.com/zunda-pixel/SamplePhotosPicker
if comment out // people.append(.init(name: "ace")), dismiss is works properly.
Is this bug or problem?
FileRepresentation.importing's 'receivedData' is already deleted. when I use.
import CoreTransferable
struct Movie: Transferable {
let url: URL
static var transferRepresentation: some TransferRepresentation {
FileRepresentation(contentType: .movie) { movie in
SentTransferredFile(movie.url)
} importing: { receivedData in
let fileName = receivedData.file.lastPathComponent
let copy: URL = FileManager.default.temporaryDirectory.appendingPathComponent(fileName)
try FileManager.default.copyItem(at: receivedData.file, to: copy)
return .init(url: copy)
}
}
}
Error Domain=NSCocoaErrorDomain Code=260 "The file “IMG_0458.mov” couldn’t be opened because there is no such file." UserInfo={NSFilePath=/private/var/mobile/Containers/Data/Application/D2E2AF9F-E879-4792-89CE-E7FB6B1B8234/tmp/.com.apple.Foundation.NSItemProvider.flbzCW/IMG_0458.mov, NSUnderlyingError=0x28389eeb0 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}