Post

Replies

Boosts

Views

Activity

Reply to Picker with ForEach
import SwiftUI struct ProviderCalendarView: View { @StateObject var viewModel = YearViewModel() @State private var selectedYear = 3 var body: some View { VStack { HStack { Picker(selection: $selectedYear) { ForEach(viewModel.years, id: \.self) { year in Text("\(year)") } } label: { } } } } } class YearViewModel: ObservableObject { @Published var years: [Int] = [] init() { createYears() } func createYears() { let now = Date() for i in 0..<4 { years.append(2023 + i) } } } I don't use Range to create an array in this case. Yet, I still get the same compiler guy.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Aug ’23
Reply to Use context menu to navigate to another view
I am able to use the contextMenu guy to navigate to another View. Do I miss something? import SwiftUI struct ContentView: View { var body: some View { NavigationStack { FirstView() } } } struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() } } struct FirstView: View { @State var goToSecond = false var body: some View { VStack { Text("FirstView") .contextMenu { Button("Go to Second View") { goToSecond.toggle() } } } .navigationDestination(isPresented: $goToSecond) { SecondView() } } } struct SecondView: View { var body: some View { VStack { Text("SecondView") } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Sep ’23
Reply to UIColorPickerViewController works incorrect in ios 17
It's not working because parent.color in Coordinator is not returned to UIColorPickerViewController. Use a Binding variable in Coordinator to pass the selected color back to UIColorPickerViewController. Besides, why do you use UIColorPickerViewController to access UIColorPickerViewController? SwiftUI has a guy named ColorPicker.
Topic: UI Frameworks SubTopic: UIKit Tags:
Sep ’23
Reply to SwiftUI tabItem Label Text Cut Off on iPad
You can simply use HStack to separate the name text and its corresponding image. import SwiftUI struct ContentView: View { var body: some View { TabView{ FirstView() .tabItem { HStack { Text("Save") .fixedSize() Image(systemName: "lock.fill") } } SecondView() .tabItem { HStack { Text("Things") .fixedSize() Image(systemName: "message.fill") } } } } } struct FirstView: View { var body: some View { Text("First") } } struct SecondView: View { var body: some View { Text("Second") } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Sep ’23
Reply to Exporting a Document with FileDocument, Not Packaged
Silly me... func fileWrapper(configuration: WriteConfiguration) throws -> FileWrapper { let fileContent = try JSONEncoder().encode(self.document) return FileWrapper(regularFileWithContents: fileContent) }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Aug ’23
Reply to Picker with ForEach
import SwiftUI struct ProviderCalendarView: View { @StateObject var viewModel = YearViewModel() @State private var selectedYear = 3 var body: some View { VStack { HStack { Picker(selection: $selectedYear) { ForEach(viewModel.years, id: \.self) { year in Text("\(year)") } } label: { } } } } } class YearViewModel: ObservableObject { @Published var years: [Int] = [] init() { createYears() } func createYears() { let now = Date() for i in 0..<4 { years.append(2023 + i) } } } I don't use Range to create an array in this case. Yet, I still get the same compiler guy.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Aug ’23
Reply to Picker with ForEach
The following works. Picker(selection: $selectedYear) { ForEach(viewModel.years.indices, id: \.self) { Text("\(viewModel.years[$0])") } } label: { }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Aug ’23
Reply to Making a Call to a Distant Struct
I think another approach is use of an ObservableObject class with onReceive(_:perform:) .
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Sep ’23
Reply to DragGesture onChange infinite loops with values 0.250 and -0.250
You aren't really telling what you are trying to do. No screenshot? Why are you applying the height value you get from the gray rectangle to the other?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Sep ’23
Reply to MapProxy conversion from screen to coords is wrong on macOS
What is screenCoord? Where does it come from?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Sep ’23
Reply to Use context menu to navigate to another view
I am able to use the contextMenu guy to navigate to another View. Do I miss something? import SwiftUI struct ContentView: View { var body: some View { NavigationStack { FirstView() } } } struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() } } struct FirstView: View { @State var goToSecond = false var body: some View { VStack { Text("FirstView") .contextMenu { Button("Go to Second View") { goToSecond.toggle() } } } .navigationDestination(isPresented: $goToSecond) { SecondView() } } } struct SecondView: View { var body: some View { VStack { Text("SecondView") } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Sep ’23
Reply to Picker value resets when in a sheet, but works fine in parent View
You aren't using the selectedValue variable in ContentView. So nobody knows how the selectedValue variable in MyPicker is supposed to affect ContentView. If the selectedValue variable in MyPicker is supposed to affect ContentView, then make it Binding.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Sep ’23
Reply to UIColorPickerViewController works incorrect in ios 17
It's not working because parent.color in Coordinator is not returned to UIColorPickerViewController. Use a Binding variable in Coordinator to pass the selected color back to UIColorPickerViewController. Besides, why do you use UIColorPickerViewController to access UIColorPickerViewController? SwiftUI has a guy named ColorPicker.
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
Sep ’23
Reply to 'unarchiveTopLevelObjectWithData' was deprecated Use unarchivedObject(ofClass:from:) instead
I've changed class FrameModel: NSObject, NSCoding { } into class FrameModel: NSObject, NSSecureCoding { class var supportsSecureCoding: Bool { true } } Muchos thankos, eskimo.
Topic: App & System Services SubTopic: General Tags:
Replies
Boosts
Views
Activity
Sep ’23
Reply to Fetch IOS Battery Data
I get a lot of hits by running a search for 'SwiftUI battery level.'
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Sep ’23
Reply to Swift Charts in ObjC project using bridging headers?
I don't have a definite answer, but I don't see why you cannnot. I have tried reading a SwiftUI file that comes with Swift Charts, using UIHostingController. That's been successful. So try that if you like.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Sep ’23
Reply to SwiftUI tabItem Label Text Cut Off on iPad
You can simply use HStack to separate the name text and its corresponding image. import SwiftUI struct ContentView: View { var body: some View { TabView{ FirstView() .tabItem { HStack { Text("Save") .fixedSize() Image(systemName: "lock.fill") } } SecondView() .tabItem { HStack { Text("Things") .fixedSize() Image(systemName: "message.fill") } } } } } struct FirstView: View { var body: some View { Text("First") } } struct SecondView: View { var body: some View { Text("Second") } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Sep ’23
Reply to unable to delete file because it's never found because.
At which line do you write a file to the triggersDirectory folder? 'triggersDirectory' appears three times, but I don't see that. You do write a file to the reflectionsURL folder.
Topic: App & System Services SubTopic: General Tags:
Replies
Boosts
Views
Activity
Oct ’23
Reply to Adding in-app purchase to originally free Mac app?
As long as your application already has a functional ability for those who use it with free of charge, I don't see a problem.
Replies
Boosts
Views
Activity
Oct ’23