Post

Replies

Boosts

Views

Activity

Save Data from Swift Playgrounds App (Mac)
How do you save data from a Swift Playgrounds App on the Mac? I get an error 'playgroundSharedDataDirectory is not supported in Swift Playgrounds' I think it's doable, some of the Swift Playgrounds tutorials remember the pages I've completed. This is with Playgrounds 4.5.1 on a Mac mini M2 Pro running OSX 14.7 (Sonoma) Ideally, I'd like to save multiple 'documents' and allow the user to select which one they want to work with. The documents don't need to be visible to other Apps. Thanks in advance
1
0
266
Jan ’25
View previous commit
I'm missing something. I have a project in Xcode 16.2. I have made two commits. I did not tag the commits. I need to compare what is in the first commit to the current state of a file. The instructions say that when comparing files there is a button at the bottom to select the commit to compare with, but I can't find that button. It looks like I can only compare the current state of the file with the last commit.
1
0
124
1w
Swift Test Parameterized Test
Is anyone seeing flaky results when using parameterized test with pairs of (input, result) data? I have several (5) tests for a given method. I create a zip sequence by zip([in1, in2, in3, in4, in5],[out1, out2, out3, out4, out5]) Sometimes, the test only runs 4 of the tests and fails to report a failure even though I deliberately place data that should cause a failure. Sometimes, even though I only select one test to run, the test explorer goes crazy into a loop and I have to clear test results to get it to stop. Following a suggestion, I disabled running tests in parallel. Xcode 16.2 / OSX 14.7 (Sonoma) / Mac mini M2 Pro
3
0
202
1w
SwiftTesting
I am using Swift Testing for TDD my project. I have a struct that contains an array of 65536 UInt8's along with other properties. I am testing methods that modify the properties of the struct including the contents of the array. In just one of my test files, any test fails (there are several in the file), the entire contents of the struct, including the array, are printed to the console. In another test file they are not. I'm don't think there are any differences to the test setup in the two files. Any idea what's going on? I'm able get the program to skip the dump to the console by copying the properties I want to test to local let constants and testing those. Thanks
1
0
181
1w
SwiftData One To Many
I'm working through the Develop In Swift tutorial at page [https://developer.apple.com/tutorials/develop-in-swift/navigation-editing-and-relationships-conclusion)] The tutorial has a one to many relationship between Friend and Movie (each friend can have at most one favorite movie and each movie can be the favorite for zero or more friends). An exercise left to the student is to use an .onDelete on the movie detail page to delete that movie as favorite. I modified the Form Form { TextField("Movie title", text: $movie.title) DatePicker("Release date", selection: $movie.releaseDate, displayedComponents: .date) if !movie.favoritedBy.isEmpty { Section("Favorited by") { ForEach(sortedFriends) { friend in Text(friend.name) } .onDelete(perform: deleteFavorites(indexes:)) } } } by adding the .onDelete clause I added private func deleteFavorites(indexes: IndexSet) { for index in indexes { context.delete(movie.favoritedBy[index]) } } to the view. This does delete the favorite movie, but it also deletes the friend. My assumption is that the selected friend should then have no favorite movie rather than being deleted There is an if in the Form that doesn't display the FAVORITED BY section if no friend has that movie as a favorite, but if I delete all the friends who had this movie as a favorite, the section remains (but is empty), until I exit the MovieDetail view and reload it There is no answer for these exercises, so I could be doing it wrong. EDIT: If I delete a movie using the app function to delete a movie, friends that have that movie as a favorite are not deleted and have their favorite movie set to None
3
0
481
2w
LinearGradient not completely filling shape
I am working through an Apple Developer SwiftUI Landmarks Tutorial using Xcode 16.2 on a M2 Pro Mac mini with OSX 14.7 (Sonoma). Under Drawing paths and Shapes, the step where they draw the background, the linearGradient is not filling the top and bottom of the hex shape. If I use a solid fill the shape is filled. I've attached a screenshot from the tutorial showing the entire shape filled with the linear gradient, a screen shot from Xcode showing the gradient not filling the top and bottom of the shape and a screen shot from Xcode showing that a solid fill does work. I found one online mention that implies that this started when the author upgraded to Xcode 16. Since the tutorial was written for Xcode 15, I assume that it worked there.
4
0
263
3w
Create Mac App from Swift Playgrounds
I am running Swift Playgrounds 4.51 under OSX 14.7 on a Mac mini M2 Pro. Under App settings for my app, I select "Install on this Mac." I get an error "An error occurred during installation Please check Console.app for further information" I can't find any entry in the console logs for this. I have a personal (free) developer account. Is there a way to create a Finder launchable app with Swift Playgrounds? I found part of the problem. My main user that I use for "normal" activity does not have administrative rights. If I give that user administrative rights, the create app succeeds and the app is added to the global Applications folder. Is there a way to have the app added to my User Application folder that then shouldn't require administrative access?
2
0
264
Jan ’25
How do you free an AudioBufferList?
In the AudioBufferList extension, there is a comment above the allocate function     /// The memory should be freed with `free()`.     public static func allocate(maximumBuffers: Int) -> UnsafeMutableAudioBufferListPointer But when I try to call free on the returned pointer, free (buffer) XCode complains: Cannot convert value of type 'UnsafeMutableAudioBufferListPointer' to expected argument type 'UnsafeMutableRawPointer?' How should the pointer be free'd? I tried free (&buffer) XCode didn't complain, but when I ran the code, I got an error in the console. malloc: *** error for object 0x16fdfee70: pointer being freed was not allocated I know the call to allocate was successful. Thanks, Mark
1
0
1.5k
Apr ’22
How to add an exception to Sandbox?
My MacOS program is printing a message in the terminal window in XCode networkd_settings_read_from_file Sandbox is preventing this process from reading networkd settings file at "/Library/Preferences/com.apple.networkd.plist", please add an exception. How do I do this? I don't see a way to add arbitrary File Access on the Signing & Capabilities tab under app setup. XCode 13.3.1 OSX Monterey 12.3.1 Mac Mini M1
6
2
8.0k
Apr ’22
What is causing this error?
I used the Xcode template to create a Mac App. I then modified ContentView.swift import SwiftUI import MapKit struct ContentView: View {     @State private var region = MKCoordinateRegion( center: CLLocationCoordinate2D( latitude: 0.0, longitude: 0.0), span: MKCoordinateSpan( latitudeDelta: 0.5, longitudeDelta: 0.5))     var body: some View {         Map(coordinateRegion: $region) } } struct ContentView_Previews: PreviewProvider {     static var previews: some View {         ContentView()     } } When I run this code, Xcode reports a runtime error: Modifying state during view update, this will cause undefined behavior. It is reported on Thread 1. This is identified with a purple warning in the issue navigator, but there is no indication of the location of the error in the source code editor. The actual map coordinates don't matter. I get the same error with different coordinates. Xcode 13.3.1 OSX Monterey 12.3.1 Mac Mini M1 P.S. When I cut the example code above from Xcode and pasted it into this message, it added extra line breaks between each line (which I manually removed). Is there a way to have the code paste as it was in Xcode? P.P.S. When I listed the software and hardware info, If I don't make it a bulleted list, the ended up being displayed on one line. If I put blank lines between them, the blank lines are displayed. Is there any way to make a vertical list without bullets?
4
0
2.9k
Apr ’22