Post

Replies

Boosts

Views

Activity

Reply to URL (via .fileImporter) to a ReadConfiguration - How to?
The .fileImporter modifier isn't for opening your SwiftUI app's documents. It's for opening other types of files in your app. The document struct's init that takes a ReadConfiguration is for opening your app's documents, either from a document picker (iOS) or by choosing File > Open (Mac). Instead of using your document struct's init that takes a ReadConfiguration, write a function to process the JSON that takes a URL as an argument. Pass the URL the file importer gives you to the JSON processing function.
Topic: App & System Services SubTopic: Core OS Tags:
Feb ’24
Reply to Developing with an older Mac
Starting April 29 Apple is going to require Xcode 15 for App Store submissions. Xcode 15 requires macOS 13+. https://developer.apple.com/news/?id=fxu2qp7b The chances are high you won't be able to submit apps with that MacBook Air. I recommend buying a Mac with an ARM processor. ARM Macs are going to be supported longer than Intel Macs.
Topic: App & System Services SubTopic: Core OS Tags:
Feb ’24
Reply to .playground to .swiftpm
For the Swift Student Challenge, either create an App playground in the Swift Playgrounds app or create a Swift Playgrounds App project in Xcode. That will give you a playground or project that meets the challenge's eligibility requirements. https://developer.apple.com/swift-student-challenge/eligibility/
Feb ’24
Reply to SwiftUI Binding property from view model to a value outside of that view model
Bindings are for SwiftUI views. Using @Binding in a view model isn't going to work. Creating a binding like Binding<Bool> in a view model isn't going to work either. For passing data from a view model to a SwiftUI view, you are on the right track with the following code in ContentViewModel: class ContentViewModel: ObservableObject { @ObservedObject var dataManager = DataManager() @Published var isOn: Bool = false } Have the view model conform to ObservableObject. Use @Published for any properties where you want the view to update when the property's value changes. The view that owns the view model uses the @StateObject property wrapper, like you have in your content view. @StateObject var viewModel = ContentViewModel() Use the @ObservedObject property wrapper to pass the view model from the content view to other views. I am not sure why the content view model needs its own isOn property. Can't it use the data manager's isOn property?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Feb ’24
Reply to SwiftUI Binding property from view model to a value outside of that view model
I made a mistake in my answer. The @ObservedObject property wrapper is for SwiftUI views. You can't use it in a view model. The following declaration: @ObservedObject var dataManager = DataManager() Should be something like @Published var dataManager = DataManager() I am not sure what you are asking in your second response. You described what you are trying to do but didn't ask a question.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Feb ’24
Reply to Detecting touching a SKSpriteNode within a touchesBegan event?
I don't see anything obviously wrong in your code. The only possible problem I see is a coordinate system problem where the values of the touch location may not be what you expect because the view and the scene have different coordinates. Set a breakpoint at the following line of code: let node:SKNode = ourScene.atPoint(location) Check if location is where you expect it to be.
Topic: Graphics & Games SubTopic: General Tags:
Feb ’24
Reply to SwiftUI Binding property from view model to a value outside of that view model
I don't have any simplified approach for you. I can tell you two things. First, to pass a view model to a SwiftUI view, do the following: Have the view model conform to ObservableObject. Add @Published properties in the view model for any properties where you want the view to update when the property's value changes. Use @StateObject in the view that owns the view model. Use @ObservedObject in the other views where you want to use the view model. Second, avoid nesting observable objects. SwiftUI views may not update properly when a property in a nested observable object has its value change. If you are unfamiliar with nested observable objects, read the following article: https://holyswift.app/how-to-solve-observable-object-problem/
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Feb ’24
Reply to Run on iOS 17 with Xcode 13.2.1
The following article shows ways to get around your issue. https://www.swiftdevjournal.com/dealing-with-failed-to-prepare-device-for-development-error-message-in-xcode/ If the workarounds in that article don't work, you will need to find a device running an older version of iOS to run your project on your Mac.
Mar ’24
Reply to After latest update: The compiler is unable to type-check this expression in reasonable time
You are doing a lot in the .onChange block. To fix the compiler error, I recommend creating a function to calculate the value of P_Sprint and call the function in the .onChange block. Breaking up the calculations into smaller chunks will also help you fix the compiler error and make the code easier to understand. If the code was working in Xcode 15.2 and you want to publish your app without making the code changes, then install Xcode 15.2. Build, archive, and submit your project in Xcode 15.2. Apple doesn't require Xcode 15.3 for App Store submissions. Use the site Xcode Releases to find Apple's download links for all Xcode versions. https://xcodereleases.com
Topic: Programming Languages SubTopic: Swift Tags:
Mar ’24
Reply to Is it Possible to save AttributedString with image to RTF doc?
To save images in a rich text document, you need to save the file as an RTFD file. An RTFD file is an RTF file with support for attachments, such as image files. You set the document type to RTF in the createRTFWithEmbeddedImage function. [.documentType: NSAttributedString.DocumentType.rtf]) If you change the document type to NSAttributedString.DocumentType.rtfd, the file should save as an RTFD file. I have not tried saving an attributed string with an image to a file so I can't guarantee there isn't more you have to do to get the image to save. But saving the file as RTFD is a start.
Topic: UI Frameworks SubTopic: SwiftUI
Jul ’24
Reply to How to use a lower version macos SDK?
Why do you want to use an older version of the macOS SDK? If you want your app to run on older versions of macOS, you can set the deployment target of the app to a lower version. The deployment target is the earliest version of macOS that can run your app. You can change the deployment target by taking the following steps: Select your project from the left side of the project window to open the project editor. Select your app target from the target list on the left side of the project editor. Click the General button at the top of the project editor. Use the menu in the Minimum Deployments section to choose the minimum macOS version for the app.
Oct ’24
Reply to URL (via .fileImporter) to a ReadConfiguration - How to?
The .fileImporter modifier isn't for opening your SwiftUI app's documents. It's for opening other types of files in your app. The document struct's init that takes a ReadConfiguration is for opening your app's documents, either from a document picker (iOS) or by choosing File > Open (Mac). Instead of using your document struct's init that takes a ReadConfiguration, write a function to process the JSON that takes a URL as an argument. Pass the URL the file importer gives you to the JSON processing function.
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
Feb ’24
Reply to Developing with an older Mac
Starting April 29 Apple is going to require Xcode 15 for App Store submissions. Xcode 15 requires macOS 13+. https://developer.apple.com/news/?id=fxu2qp7b The chances are high you won't be able to submit apps with that MacBook Air. I recommend buying a Mac with an ARM processor. ARM Macs are going to be supported longer than Intel Macs.
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
Feb ’24
Reply to .playground to .swiftpm
For the Swift Student Challenge, either create an App playground in the Swift Playgrounds app or create a Swift Playgrounds App project in Xcode. That will give you a playground or project that meets the challenge's eligibility requirements. https://developer.apple.com/swift-student-challenge/eligibility/
Replies
Boosts
Views
Activity
Feb ’24
Reply to SwiftUI Binding property from view model to a value outside of that view model
Bindings are for SwiftUI views. Using @Binding in a view model isn't going to work. Creating a binding like Binding<Bool> in a view model isn't going to work either. For passing data from a view model to a SwiftUI view, you are on the right track with the following code in ContentViewModel: class ContentViewModel: ObservableObject { @ObservedObject var dataManager = DataManager() @Published var isOn: Bool = false } Have the view model conform to ObservableObject. Use @Published for any properties where you want the view to update when the property's value changes. The view that owns the view model uses the @StateObject property wrapper, like you have in your content view. @StateObject var viewModel = ContentViewModel() Use the @ObservedObject property wrapper to pass the view model from the content view to other views. I am not sure why the content view model needs its own isOn property. Can't it use the data manager's isOn property?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Feb ’24
Reply to SwiftUI Binding property from view model to a value outside of that view model
I made a mistake in my answer. The @ObservedObject property wrapper is for SwiftUI views. You can't use it in a view model. The following declaration: @ObservedObject var dataManager = DataManager() Should be something like @Published var dataManager = DataManager() I am not sure what you are asking in your second response. You described what you are trying to do but didn't ask a question.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Feb ’24
Reply to Detecting touching a SKSpriteNode within a touchesBegan event?
I don't see anything obviously wrong in your code. The only possible problem I see is a coordinate system problem where the values of the touch location may not be what you expect because the view and the scene have different coordinates. Set a breakpoint at the following line of code: let node:SKNode = ourScene.atPoint(location) Check if location is where you expect it to be.
Topic: Graphics & Games SubTopic: General Tags:
Replies
Boosts
Views
Activity
Feb ’24
Reply to SwiftUI Binding property from view model to a value outside of that view model
I don't have any simplified approach for you. I can tell you two things. First, to pass a view model to a SwiftUI view, do the following: Have the view model conform to ObservableObject. Add @Published properties in the view model for any properties where you want the view to update when the property's value changes. Use @StateObject in the view that owns the view model. Use @ObservedObject in the other views where you want to use the view model. Second, avoid nesting observable objects. SwiftUI views may not update properly when a property in a nested observable object has its value change. If you are unfamiliar with nested observable objects, read the following article: https://holyswift.app/how-to-solve-observable-object-problem/
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Feb ’24
Reply to SwiftUI NavigationView force "both panels side by side" split behaviour
According to the following article: https://serialcoder.dev/text-tutorials/swiftui/navigation-view-style-in-swiftui/ Use the columns navigation view style to have two panels side by side on iPhones with screens big enough to show two panels. NavigationView { … } .navigationViewStyle(.columns)
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Mar ’24
Reply to Products.product always returns an empty array
I had a similar issue, which you can see in the following post: https://developer.apple.com/forums/thread/740539 It turns out I had to add a Mac build to my app in TestFlight and get the build approved for external testing to get the products to fetch properly.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Mar ’24
Reply to Run on iOS 17 with Xcode 13.2.1
The following article shows ways to get around your issue. https://www.swiftdevjournal.com/dealing-with-failed-to-prepare-device-for-development-error-message-in-xcode/ If the workarounds in that article don't work, you will need to find a device running an older version of iOS to run your project on your Mac.
Replies
Boosts
Views
Activity
Mar ’24
Reply to FileDocument - open another file in the same directory as selected file
Use the FileWrapper class to store your document as a package of files and folders that appears as a single file in the Finder. The following article provides an introduction to working with file wrappers in a SwiftUI app: https://www.swiftdevjournal.com/using-file-wrappers-in-a-swiftui-app/
Topic: App & System Services SubTopic: General Tags:
Replies
Boosts
Views
Activity
Mar ’24
Reply to After latest update: The compiler is unable to type-check this expression in reasonable time
No one can give you an answer until you show the code that is causing the compiler error.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Mar ’24
Reply to After latest update: The compiler is unable to type-check this expression in reasonable time
You are doing a lot in the .onChange block. To fix the compiler error, I recommend creating a function to calculate the value of P_Sprint and call the function in the .onChange block. Breaking up the calculations into smaller chunks will also help you fix the compiler error and make the code easier to understand. If the code was working in Xcode 15.2 and you want to publish your app without making the code changes, then install Xcode 15.2. Build, archive, and submit your project in Xcode 15.2. Apple doesn't require Xcode 15.3 for App Store submissions. Use the site Xcode Releases to find Apple's download links for all Xcode versions. https://xcodereleases.com
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Mar ’24
Reply to Is it Possible to save AttributedString with image to RTF doc?
To save images in a rich text document, you need to save the file as an RTFD file. An RTFD file is an RTF file with support for attachments, such as image files. You set the document type to RTF in the createRTFWithEmbeddedImage function. [.documentType: NSAttributedString.DocumentType.rtf]) If you change the document type to NSAttributedString.DocumentType.rtfd, the file should save as an RTFD file. I have not tried saving an attributed string with an image to a file so I can't guarantee there isn't more you have to do to get the image to save. But saving the file as RTFD is a start.
Topic: UI Frameworks SubTopic: SwiftUI
Replies
Boosts
Views
Activity
Jul ’24
Reply to How to use a lower version macos SDK?
Why do you want to use an older version of the macOS SDK? If you want your app to run on older versions of macOS, you can set the deployment target of the app to a lower version. The deployment target is the earliest version of macOS that can run your app. You can change the deployment target by taking the following steps: Select your project from the left side of the project window to open the project editor. Select your app target from the target list on the left side of the project editor. Click the General button at the top of the project editor. Use the menu in the Minimum Deployments section to choose the minimum macOS version for the app.
Replies
Boosts
Views
Activity
Oct ’24