Post

Replies

Boosts

Views

Activity

Reply to can't use @Environment for Binding?
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 })) } }
Jun ’23
Reply to I want to use ForEach in RegexBuilder like SwiftUI
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
Aug ’22
Reply to How to Active NavigationLink at Change Data in iOS 16
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")       }     }   } }
Aug ’22
Reply to How to use Multi NavigationLink in One Cell of List?
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)       }     }   } }
Aug ’22
Reply to How load Video with New(iOS 16) PhotosPicker? loadTransferable(type:)
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"}}
Jun ’22