Swift Playgrounds

RSS for tag

Learn and explore coding in Swift through interactive learning experiences on the Swift Playgrounds app for iPadOS and macOS.

Swift Playgrounds Documentation

Posts under Swift Playgrounds tag

119 Posts
Sort by:
Post not yet marked as solved
10 Replies
5.6k Views
I just started to learn how to code with "Intro to App Development With Swift" from Apple on iBooks and whenever I try to edit one of the given practice files, a window pops up saying "The document “02_Naming.playground” could not be saved. The file has been changed by another application. Click Save Anyway to keep your changes and save the changes made by the other application as a version, or click Revert to keep the changes from the other application and save your changes as a version. You can also click Save As to save your changes to a different file." This error pops up every time I type a keystroke in the file. How do I fix this?
Posted
by
Post not yet marked as solved
1 Replies
1.2k Views
I am following Jonathan Penn’s demo at WWDC2019 where he tabs through code completion choices with the external iPad keyboard. The difference is that this does not work with the Magic Keyboard on my 2020 iPad Pro 11” - the Tab key has no effect whatsoever on the Playground page whilst I am coding. I have to tap on the code completion to choose it. I can’t see any setting that I need to make but cant believe this is what it supposed to happen.
Posted
by
Post not yet marked as solved
20 Replies
50k Views
I'm practicing a swift 5 class, and have this issue: Could not launch “I AM RICH” Domain: IDEDebugSessionErrorDomain Code: 3 Failure Reason: The operation couldn’t be completed. Unable to launch com.superdie.I-AM-RICH because it has an invalid code signature, inadequate entitlements or its profile has not been explicitly trusted by the user. User Info: {     DVTRadarComponentKey = 855031;     RawLLDBErrorMessage = "The operation couldn\U2019t be completed. Unable to launch com.superdie.I-AM-RICH because it has an invalid code signature, inadequate entitlements or its profile has not been explicitly trusted by the user."; } I'm not sure what can I do, some help would be nice :)
Posted
by
Post not yet marked as solved
4 Replies
1.1k Views
Hi guys, is Swift Playgrounds same as Xcode, I mean the code that I write in Xcode I can paste it into Swift Playgrounds?
Posted
by
Post not yet marked as solved
4 Replies
2.1k Views
I would like to know if I can add a app I have made in swift playgrounds on the homescreen. I know this is unlikely but is there a work around by adding a shortcut to the homescreen that opens straight to the app I made? If I need to clarify let me know!
Posted
by
Post not yet marked as solved
12 Replies
3.2k Views
Was doing the tutorials from Swift Playgrounds new lesson "Keep going with Apps" and on the "Bindings" chapter was asked to put a ColorPicker view. To see the color options I should run the app instead of seeing it in the preview. I tried to do that but I don't get a response from Playgrounds... Has someone had the same problem while doing this lesson?
Posted
by
Post not yet marked as solved
2 Replies
2.1k Views
Hi, I have a problem with making a swift playgrounds app walkthrough. I followed the steps exactly and modified my Package.swift a bit (in the targets section): .executableTarget(name: "App", dependencies: ["Guide"], path: "App"),         .target(             name: "Guide",             path: "Guide",             resources: [             .process("Guide.tutorial"),             ]) Now when I open the project in Playgrounds I get this error: public headers ("include") directory path for 'Guide' is invalid or not contained in the target Any help would be appreciated. Thanks
Posted
by
Post not yet marked as solved
1 Replies
1.6k Views
I am trying to develop an App in Swift Playgrounds that will use the SwiftMQTT package. SwiftMQTT needs to open an outgoing network connection to connect the app to an MQTT server. To integrate the package, I wrote a basic manager class as an observable object. When I try to make a connection with this manager, Swift Playgrounds appears to block the connection. Searching around, I found that this was likely due to sandboxing but couldn't figure out how to fix it in Swift Playgrounds. To test this idea, I moved my manager class over to XTools and created a test app to make the connection. Initially, I got the same error. However, XTools let me make the needed sandbox setting on the Signing & Capabilities page of the app. Click/checkmarking "Outgoing Connections (Client)" under Network solved my problem there. I would still like to do this in Playgrounds but can't for the life of me figure out how to open up the sandbox. Can anybody point me there (or wave me off if this is currently impossible).
Posted
by
Post not yet marked as solved
1 Replies
939 Views
I want to make it like this How to disable the button that open the side bar, I only need the content and the detail view. I don't need the sidebar view. Below is my code import SwiftUI @available(iOS 16.0, *) struct Screen: View { @ObservedObject var userData = UserData() @State private var isIntroShown = true @State var Itema: Bool = false @State private var showFoodDetail = false @State var rb: Bool = false @State var Setting: Bool = false @State var Recipe: Bool = false @Environment(\.defaultMinListRowHeight) var minRowHeight @Environment(\.colorScheme) var colorScheme @State private var searchText = "" private let adaptiveColumns = [ GridItem(.adaptive(minimum: 170)) ] var columns = Array(repeating: GridItem(.flexible(), spacing: 10), count: 2) var filteredRooms: [Room] { if searchText.isEmpty { return userData.rooms } else { return userData.rooms.filter { room in let foodNames = room.food.map { $0.name.lowercased() } return room.name.lowercased().contains(searchText.lowercased()) || foodNames.contains { $0.contains(searchText.lowercased()) } } } } @State private var columnVisibility = NavigationSplitViewVisibility.doubleColumn var body: some View { NavigationSplitView (columnVisibility: $columnVisibility){ } content: { ScrollView{ GridView() .padding(.horizontal) .padding(.bottom, 20) }.toolbar { ToolbarItem(placement: .bottomBar){ Button(action:{self.Itema = true}) { HStack { Image(systemName: "plus.circle.fill").resizable().frame(width: 20, height: 20).foregroundColor(.white) Text("New Item").foregroundColor(.white).bold() } } .sheet(isPresented: self.$Itema){ NewItem(userData: self.userData) } } ToolbarItem(placement: .bottomBar){ Button(action:{self.rb = true}) { HStack { Text("New Room").foregroundColor(.white) } } .sheet(isPresented: self.$rb){ NewRoom(userData: self.userData) } } ToolbarItem(placement: .navigationBarTrailing){ Button(action:{self.Setting = true}) { HStack { Image(systemName: "gear").foregroundColor(.white) } } .sheet(isPresented: self.$Setting){ NavigationView { NewItem( userData: userData) .navigationBarItems(trailing:Button(action: { self.Setting = false }){ Text("Done") } ) } } } } .background(Color(red: 203/255, green: 237/255, blue: 207/255)) } detail: { ZStack { Text("") } .frame(maxWidth: .infinity, maxHeight: .infinity) .background(Color(red: 220/255, green: 247/255, blue: 234/255)) } .searchable(text: $searchText) } }
Posted
by
Post not yet marked as solved
3 Replies
869 Views
Since updating to Big Sur 11.7.5 I am unable to preview any Views or run the Playground both continue to create Crash Reports until Xcode is stopped. The Preview panel remains blank or the Playground never runs. Crash Report attached below which indicates that the update has moved a Library called AddressBook and Xcode can no longer locate it. NPKCompanionAgent_2023-04-06-140115_Johns-iMac.crash
Posted
by
Post not yet marked as solved
4 Replies
2.4k Views
Have downloaded playgrounds 4.3 to my iPad Air running ipados 16.5. Trying to use playground “Get started with Apps” but receiving message “Unsupported file format Get Started with Apps.swiftpm cannot be opened in Swift Playgrounds”. I do not have Mac or windows PC so am stuck! Help ??
Posted
by
Post not yet marked as solved
2 Replies
1.1k Views
Is there a way to make a .swiftpm app only available on the iPad? I can see where I would restrict it in the autogenerated Package.swift, but there's nowhere in the Swift Playgrounds or Xcode 14 interface that I can find that will let me restrict it to iPad only. It's causing my app to get rejected by the App Store team, as the iPhone version is too crowded... but it's designed for iPad... I just need to be able to specify that somewhere...
Posted
by
Post marked as solved
1 Replies
357 Views
Hi! I'm learning coding in swift with Playgrounds. In the middle of a chapter, I 've lost the tutorial. I tried to close and re open the file but the tutorial is not displaying. Is Anyone knows how to retrieve it? Thank's!
Posted
by
Post not yet marked as solved
1 Replies
632 Views
steps to reproduce: create a new iPad Playgrounds project implement the minimum viable app using DocumentGroup import SwiftUI import UniformTypeIdentifiers struct TextDocument: FileDocument { var text: String init(text: String = "") { self.text = text } static var readableContentTypes: [UTType] { [.plainText] } init(configuration: ReadConfiguration) throws { guard let data = configuration.file.regularFileContents, let string = String(data: data, encoding: .utf8) else { throw CocoaError(.fileReadCorruptFile) } text = string } func fileWrapper(configuration: WriteConfiguration) throws -> FileWrapper { let data = text.data(using: .utf8)! return .init(regularFileWithContents: data) } } @main struct MyApp: App { var body: some Scene { DocumentGroup(newDocument: TextDocument()) { file in TextEditor(text: file.$document.text) } } } I can compile and run the app, and use it to open and edit or create new plain text documents, but the App Preview crashes, saying "The requested index was outside the bounds of the array." and there's a red error badge on @main I assume this is a bug, and I've submitted a feedback (FB12194610) but I'm looking for ways to work around it in the meantime. There are two annoyances the red error badge obfuscates when i really do have errors in my code I don't have previews If I comment out the DocumentGroup code and insert a WindowGroup I can make the preview successfully load long enough that I can pause it. This fixes the error badge problem, but pausing the App Preview pauses all the view previews as well. And every time I run the project it restarts the previews. And I have to run the project pretty often because I can't use the previews! So I'm hoping there's a better workaround, either by more permanently disabling App Preview, or with something like the App Preview equivalent of PreviewProvider to give me some control over how the App Preview renders.
Posted
by
Post not yet marked as solved
3 Replies
660 Views
I need to read the files names into the DiagnosticReports directory, I've tried a some examples from StackOverflow, including below, but I simply cant make it to work: // Create a FileManager instance let fileManager = FileManager.default let documentsURL = fileManager.urls(for: .libraryDirectory, in: .userDomainMask)[0] do { let fileUrls = try fileManager.contentsOfDirectory(at:documentsURL, includingPropertiesForKeys: nil) // process files print(fileUrls) } catch { print("Error while enumerating files \(documentsURL.path): \(error.localizedDescription)") } } listDir(dir: "/Library/Logs/DiagnosticReports") That was the most successful one I got, any other simply won't show anything.
Posted
by
Post not yet marked as solved
3 Replies
659 Views
I see this happening in other threads but none of those solutions have worked for me. I'm new to Swift (my apologies) and attempting a simple test to get a string response from a service I have running on my machine. (This service show results from a browser and Postman so I'm sure it's working.) This is my code: let url = URL(string: "http://127.0.0.1:8080/stuff/ping")! var request = URLRequest(url: url) request.httpMethod = "GET" print("creating ping task...") let task = URLSession.shared.dataTask(with: request) { data, response, error in print("processing ping result...") if let data = data { let str = String(decoding: data, as: UTF8.self) print(str) } else if let error = error { print("HTTP Request Failed \(error)") } } print("resuming ping task...") task.resume() When I run that in a playground, it works! The console shows: creating ping task.... resuming ping task... processing ping result... One ping only, Vasily But from within a XCTest, it does not: Test Suite 'NetworkTests' started at 2023-06-02 08:24:46.007 Test Case '-[StuffTests.NetworkTests testPing]' started. creating ping task... resuming ping task... Test Case '-[StuffTests.NetworkTests testPing]' passed (0.002 seconds). Test Suite 'NetworkTests' passed at 2023-06-02 08:24:46.010. Executed 1 test, with 0 failures (0 unexpected) in 0.002 (0.002) seconds I've set the info of the project according to what I've seen in other posts so that it can access a local host (?): I appeal to you for help in understanding and fixing this. thank you!
Posted
by
Post not yet marked as solved
0 Replies
719 Views
I randomly have errors with any playground. Is this just a random timeout with iCloud? I checked perms and my account has read & write to the playground and the folder it's (Playgrounds in iCloud Drive). I've never opened a playground and found anything missing, so it must be saving. I was not on VPN with this most recent error (though sometimes I am). I'm on an M1 Pro Mac.
Posted
by