Post

Replies

Boosts

Views

Activity

PDFKit + SwiftUI
Hello and thanks for reading my post. I have been trying hard to generate a PDF from a SwiftUI view on a button press. Looked at the PDFKit documentation, understood that PDFView, PDFDocument and PDFPage are important classes. However, I couldn't find any examples of how to use them in SwiftUI or Swift. Basically, given a SwiftUI view (or a Swift struct), how to create a new SwiftUI view that displays the generated PDF? The pdf can contain charts, layouts, etc.
1
0
1.1k
Jun ’23
SwiftUI view printout on paper
Hello and thanks for reading my post. I have a SwiftUI view, the users should be able to click a button and take printout of that view. Clicking on the button should open the standard print sheet (select printer, pages, layout, etc.). How can I implement such a functionality? I have been trying hard without any success. Please help. It is an iPad app, using Xcode 14.3
5
1
1.5k
Jun ’23
Bug in SwiftUI List view
In the following code, click/touch anywhere on any row of the list deletes that row. This is not expected. Only the click/touch on the "xmark" button should delete that row. import SwiftUI struct MainView: View { private let arr: [String] = ["one", "two", "three"] var body: some View { List(arr, id: \.self) {item in SecView(name: item) } } } struct SecView: View { var name: String @State private var show = true var body: some View { if show { HStack { Text(name) Button(action: { show = false }, label: { Image(systemName: "xmark") }) .border(.yellow) } } } } @main struct XApp: App { var body: some Scene { WindowGroup { MainView() } } } Please check. I ran the above code for iPAD air (5th generation).
1
0
1k
May ’23
SwiftUI Timer not working inside Menu bar extra
Hello, I am new to the Swift and the SwiftUI. I want to build a MacOS app for learning purpose. Looks like I am stuck, so looking for some help. The code below does not execute the print statement. Why is the timer not working? What am I missing? Thanks in advance. struct CustomView: View {         let timer = Timer.publish(every: 1, on: .current, in: .common).autoconnect()     private var nums: [String] = ["one", "two"]         var body: some View {         ForEach(nums, id: \.self) {num in             Text(num)         }         .onReceive(timer) { time in // why is this not working?             print("time is \(time)")         }     } } @main struct Writer: App {     var body: some Scene {         MenuBarExtra("Writer util", systemImage: "pencil.line") {             CustomView()         }         .menuBarExtraStyle(.menu)     } }
6
1
1.6k
Mar ’23
Learning path for MacOS app development
Hello everyone, I am new to the app development. My goal is to develop professional apps for the MacOS. I have learned some Swift and SwiftUI on my own. Also, watched some videos here and there. Apple tutorials are also scattered. I feel I know some things, but not enough to create the apps that I want. A lot of my time goes into searching things, which kills my interest. Is there a learning path (things to learn in sequence) for MacOS app development? Example: learn swift learn swiftUI design patterns? some frameworks, maybe? Please suggest. Thanks,
3
0
697
Jan ’23
How SwiftUI Table sorting works ?
Hello everyone, I am new to the Swift and the SwiftUI. Trying to understand how sorting works on SwiftUI Table view. The following code does what I intend to do, but I am not able to understand how does it actually work. Need help with the answers for the questions posted below the code. import SwiftUI struct Person: Identifiable {     let givenName: String     let familyName: String     let emailAddress: String     let id = UUID() } private var people = [     Person(givenName: "f1", familyName: "l1", emailAddress: "e1@example.com"),     Person(givenName: "f2", familyName: "l2", emailAddress: "e2@example.com"),     Person(givenName: "f3", familyName: "l3", emailAddress: "e3@example.com") ] struct ContentView: View {     @State private var selected = Set<Person.ID>()  // Question 1     @State private var sortOrder = [KeyPathComparator(\Person.givenName)]     var body: some View {         Table(people, selection: $selected, sortOrder: $sortOrder) {             TableColumn("Given name", value: \.givenName)             TableColumn("Family name", value: \.familyName)             TableColumn("Email", value: \.emailAddress)         } // Question 2         .onChange(of: sortOrder) { newOrder in             people.sort(using: newOrder)         }     } } Question 1 : I want to be able to sort by all the columns. How many KeyPathComparators should be in the sortOrder array? Question 2: What is the value of newOrder? Is it same as the sortOrder? What does it contain? Question 3: sortOrder contains the comparator for only givenName. How does the above code able to provide sort functionality for all the columns?
3
0
1.8k
Jan ’23