Post

Replies

Boosts

Views

Activity

Reply to Implementing Renaming and Reordering in SwiftUI Sidebar for macOS App
Please provide more details on "the ability to rename an item with the Return key (behavior 2) stops working". What exactly happens when you select a list item and press the Return key? What are you using with your navigation links: NavigationSplitView, NavigationStack, or NavigationView? Show your code for the functions moveItem and renameItem. I tested some code in an app of mine that lets people rearrange and rename list items, and I could not replicate the behavior you see. I was able to select an item, press the Return key, and rename the item. My code uses NavigationView because my app must support macOS 12. My code for the navigation link binds the text field to the selected item, the item property in your item view, instead of using a separate property, such as your newTitle property.
Jan ’24
Reply to Xcode 14.2 Running Extremely Slow
The 8 GB of RAM and a 5400 rpm hard drive are not good specs for running Xcode. I have a similar model of iMac with 16 GB of RAM and Xcode on an external SSD, and Xcode 14.2 runs decently. It's not blazing fast, but it's not painfully slow either. If your iMac is a 27 inch model, you can add RAM to it. Doing that and moving your boot drive to an external SSD will improve things.
Dec ’23
Reply to How can I solve build failed error?
The usual causes of build errors are errors in your code and missing frameworks. You can see the build errors in Xcode's issue navigator. Press Cmd-5 in Xcode to show the issue navigator. No one here can give you an answer right now based on the information you provided. For anyone to help you, you must list the errors and show the source code for any compiler errors. Use text, not screenshots, to show your errors and code. Text is easier to read than trying to read text from a screenshot. The following article may help you get started with fixing the errors in your code: https://www.swiftdevjournal.com/why-wont-my-xcode-project-build/
Dec ’23
Reply to How to create paginated PDF from NSTextView?
Creating a PDF with multiple pages isn't easy. You are going to have use Quartz (CoreGraphics). Create a PDF context. Do the following until you reach the end of the text: Determine how much text can fit on a page. Call the PDF context's beginPage function. Draw the page of text. Call the PDF context's endPage function. Update the location in the text to start drawing the next page. The following article explains what you have to do to create a multiple page PDF with Quartz and Core Text: https://www.meandmark.com/blog/2016/08/creating-pdfs-with-core-text-and-quartz/ The TPPDF Swift package can be used to create PDF files. You will probably find it easier to use than to create a PDF with Quartz. https://github.com/techprimate/TPPDF
Dec ’23
Reply to No Observable Object of type...found
I have not used the Observation framework or SwiftUI's image renderer, but I think you need to move your pdfReport function out of the view model and into a SwiftUI view. I don't think you can create the image renderer in a view model. One question about your code. Why do you pass an array of Person objects to pdfReport and have the personsToPrint property in the ViewModel class? You don't use the person argument in the pdfReport function. Wouldn't it be easier to get rid of the personsToPrint property and use the array of Person objects in the for loop? Then you wouldn't have to worry about the array being nil. @MainActor func pdfReport(people: [Person]) { for person in people { // Rest of code omitted } }
Dec ’23
Reply to Beginner Debug Problem
You have to wrap the variable you are logging with the @ character, @i@, instead of $i. The message you log should be the following: The current value for I is: @i@ Read the following article for more details: https://www.swiftdevjournal.com/replace-swift-print-statements-with-xcode-breakpoint-actions/ The article talks about Swift code, not C++, but the material applies to C++ code as well.
Dec ’23
Reply to why my form does not work
Provide more specifics on what you mean by "form does not work". What do you expect to see? What do you see when you run your app? I suggest moving your networking code out of the form into its own function. Call the function when someone taps the Sign In button.
Dec ’23
Reply to Binding a Textfield to a name in a Object
You have two problems in your code. First, the @State property wrapper is for structs, not classes. You need to use the @StateObject property wrapper for classes. Either use @StateObject in the view or make QuizPlayer a struct instead of a class and remove @Published from the QuizPlayer fields. Second, you are overcomplicating things with binding a player's name to a text field. Instead of accessing the players using an index, go through the array of players and bind each player's name to the text field. The code will look similar to the following: ForEach(quizPlayers, id:\.self) { $player in TextField("Player Name: ", text: $player.name) } The $player argument gives you the current player so you do not have to access the quizPlayers array or deal with array indexes. Keep in mind I typed the code from memory so I cannot guarantee it will work correctly if you copy and paste it in your code. You may need to change $player to player. But the code gives you an idea of what you need to do to bind the player's name to the text field.
Nov ’23
Reply to Problems with PDFKit
I do not see anything wrong with the logic in the code you supplied. I see two possible formatting errors: importing the two frameworks on the same line and declaring the url property on the same line as the struct declaration. Does the code build if you place the import statements on separate lines and the url declaration on its own line? import SwiftUI import PDFKit struct PDFViewerView: UIViewRepresentable { var url: URL func makeUIView(context: Context) -> PDFView { let pdfView = PDFView() pdfView.document = PDFDocument(url: self.url) return pdfView } func updateUIView(_ uiView: PDFView, context: Context) { // Update the view. } }
Nov ’23
Reply to Problem with starting my Project
Would you recommend starting with Swift or SwiftUI. SwiftUI uses Swift so you have to know both. The question you really have is using UIKit or SwiftUI. For a new project I would recommend SwiftUI. Read the following article for additional details: https://www.swiftdevjournal.com/should-i-learn-swift-or-swiftui/ how I could download the App to my own Phone. is the 100€ a year Apple Developer enrolment necessary ? Or is there a free way without downloading it every week. No, a paid developer account is the only way to avoid having to reinstall your app every week. is there a way to publish the App as private. So only I see it myself ? Use unlisted app distribution to make the app private. https://developer.apple.com/support/unlisted-app-distribution/
Nov ’23
Reply to problem with .FileImporter in fisical divice
Paste the code as text and format it as a code block. Text in a code block is easier to read than a screenshot. Plus, people can copy and paste the code when it is in a code block. The code block button is the 4th button from the left in the list of buttons below the text editor on the forum. You can also add three backticks on the line above and below the code. https://www.markdownguide.org/extended-syntax/#fenced-code-blocks I am going to put, my code, as I say, in the breakpoints everything works fine, it does not show any errors, it simply does not load the file, nor does its name appear, when I pass it to testfligh and install it Please clarify one thing. When you run the project from Xcode on your iPad, are you able to open the file? Does the problem occur only when you install your app from TestFlight and run it on the iPad? My guess is the reason the file does not load and does not show any errors is the condition in the guard statement is false. Here is the code. guard let archivoURL1 = try result.get() as? URL else { return } If the call to result.get fails, you return before you get to any code that prints error messages. That is why no errors appear in Xcode's console.
Nov ’23
Reply to problem with .FileImporter in fisical divice
What happens when you run the app from Xcode on your iPad? Are you able to open the file? If you can, that narrows the problem down to TestFlight. I recommend running the app from Xcode on your iPad and set a breakpoint in your file importing code. If you step through the code line by line, Xcode's console should show error messages if there's a problem with opening the file. Show your file importing code. Without the code, people here will just be guessing about the cause of the problem.
Nov ’23