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
Post
Replies
Boosts
Views
Activity
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.
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
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
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
When working on a project, I would like to open a file from a previous project in a side-by-side window for reference, so I can view and adapt parts of the previous file into a file in the current project. I don't want the previous file to be part of the current project. Is this possible? If so, how?
Is there a way to create a Date constant from year, month and day? The only constructors that show up are .now and those based on some timeInterval. I'm trying to initialize some test data with known dates.
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.
My M2 Pro Mac mini with OSX 14.7 just updated to Swift Playgrounds 4.6.1. Now the :Learn to Code & Build Apps screen is limited in size and can't be zoomed. There is no way to scroll horizontally and I can't view the whole screen.
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?
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
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
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?
If you use a TabView in a Preferences scene you get nice looking tabs.
If you use a TabView in the main scene, the tabs are plain.
Is there a way to fix that?
Thanks, Mark
I have seen code where a struct is defined and then in the same file an extension for the same struct is defined. Why not just include the contents of the extension in the original struct definition?