Post

Replies

Boosts

Views

Activity

Reply to Using structs with TextField
class FinalBluePrint: ObservableObject {  @Published var currentGrade: Double = 5;  @Published var desiredGrade : Double = 0;  @Published var finalWeight : Double = 0;  var finalNeededGrade : Double {   let desiredGrade = self.desiredGrade;   let currentGrade = self.currentGrade;   let finalWeight = self.finalWeight;   let finalNeededGrade = (desiredGrade - currentGrade * (100 - finalWeight)) / finalWeight;   return finalNeededGrade  } } struct ContentView: View {  @StateObject var final = FinalBluePrint()  var body : some View {   NavigationView {    VStack {     TextField("Current Grade", value: $final.currentGrade, format: .number).keyboardType(.decimalPad);     TextField("Desired Grade", value: $final.desiredGrade, format: .number).keyboardType(.decimalPad);     TextField("Final Weight", value: $final.finalWeight, format: .number).keyboardType(.decimalPad);     Text(final.currentGrade, format: .number);     Text(final.finalNeededGrade, format: .number);    }   }  } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jun ’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"}}
Topic: Programming Languages SubTopic: Swift Tags:
Jun ’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)       }     }   } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
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")       }     }   } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Aug ’22
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
Topic: Programming Languages SubTopic: Swift Tags:
Aug ’22
Reply to Having problems trying out the example code in this session
I face to same issue in Playground. Normal Project can compile it.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jun ’22
Reply to Why isn't my "Add button" not working?
List in List does not work well. You should change code like below code List { Button("ADD") { } Section { ForEach(data) { datum in } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jun ’22
Reply to Using structs with TextField
class FinalBluePrint: ObservableObject {  @Published var currentGrade: Double = 5;  @Published var desiredGrade : Double = 0;  @Published var finalWeight : Double = 0;  var finalNeededGrade : Double {   let desiredGrade = self.desiredGrade;   let currentGrade = self.currentGrade;   let finalWeight = self.finalWeight;   let finalNeededGrade = (desiredGrade - currentGrade * (100 - finalWeight)) / finalWeight;   return finalNeededGrade  } } struct ContentView: View {  @StateObject var final = FinalBluePrint()  var body : some View {   NavigationView {    VStack {     TextField("Current Grade", value: $final.currentGrade, format: .number).keyboardType(.decimalPad);     TextField("Desired Grade", value: $final.desiredGrade, format: .number).keyboardType(.decimalPad);     TextField("Final Weight", value: $final.finalWeight, format: .number).keyboardType(.decimalPad);     Text(final.currentGrade, format: .number);     Text(final.finalNeededGrade, format: .number);    }   }  } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jun ’22
Reply to How to Active NavigationLink at Change Data in iOS 16
https://developer.apple.com/wwdc22/10054 doesn't explain multi NavigationLink in one cell.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jun ’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"}}
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jun ’22
Reply to ToolbarItemGroup(placement: .keyboard) is not showed with Sheet
Is this bug or problem?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jun ’22
Reply to [SwiftUI]Binding, dismiss Bug?
if comment out // people.append(.init(name: "ace")), dismiss is works properly.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Aug ’22
Reply to How load Video with New(iOS 16) PhotosPicker? loadTransferable(type:)
This problem fixed in iOS 16 beta 5. thanks https://github.com/zunda-pixel/SamplePhotosPicker
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Aug ’22
Reply to [PhotosPicker Bug iOS 16.0 beta 2] only deselect doesn't change PhotosPickerItem
same in Beta 5.
Replies
Boosts
Views
Activity
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)       }     }   } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
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")       }     }   } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Aug ’22
Reply to ToolbarItemGroup(placement: .keyboard) is not showed with Sheet
This bug is fixed in iOS 16 beta 5.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Aug ’22
Reply to Regex Error Thread 1: EXC_BREAKPOINT (code=1, subcode=0x22a78b848)
This problem is not happened when run again.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Aug ’22
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
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Aug ’22
Reply to Binding with ForEach or List doesn't work anymore when using @Observable macro
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
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jun ’23