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

129 Posts
Sort by:
Post not yet marked as solved
1 Replies
75 Views
I've noticed Playgrounds crashing a lot lately, both on iPad and Mac. I have many Macs, Intel & M1, and 2 iPads, 7th Gen and 10.5" Pro. It's noticeably sluggish at the best of times progressively getting worse the last few updates, but worse than that it is hard crashing, losing data in the process. Anyone else seeing this? Not the end of the world, I'm a dev and use Xcode for anything substantial but I like to use Playgrounds on the iPad sometimes when I want to pop a quick idea down. I also plan to start creating playgrounds to help kids get into programming, so hoping this useful app isn't being neglected.
Posted Last updated
.
Post not yet marked as solved
1 Replies
138 Views
I am trying to include custom symbol resources in a swift package for use in other projects. I have read the documentation here: https://developer.apple.com/documentation/xcode/bundling-resources-with-a-swift-package However there is no example code and I have created a very simple project to try and get this working but it does not. .target( name: "TestLibrary", resources: [.process("Resources/Media.xcassets")] ), This is in the Package.swift file and the path relative to the Package.swift file is Sources/TestLibrary/Resources/Media.xcassets. There's a GitHub project with an example custom SF Symbol SVG (but this may not be available in the future): https://github.com/kudit/TestLibrary Including this as a package in a blank Swift Playgrounds App project and just importing the TestLibrary and including TestImageView() in the ContentView technically works (it shows the system full star image, but none of the ways of rendering the test symbol as recommended works. It does work for a few of the options in the #Preview when viewing the project in Xcode. Anyone have any suggestions or know how to get the resources to be accessible from outside the module? I have tried both the .copy( option as well as the .process( option and neither seem to work.
Posted
by kudit.
Last updated
.
Post not yet marked as solved
2 Replies
208 Views
Hello All, I happen to remove "Playgrounds" folder from my iCloud drive, and afterwards Playground is no longer functioning but repeatedly crashes. It was okey before deletion, but now any operation to create or download playground then Playground App crashes all the time. Issue not resolved even creating same name folder by manual, Issue not resolved even re-install Playground - folder in iCloud will not created. I guess I need to fully uninstall PlayGround completely, then start from scratch to let Playground App to hold init step to generate required folder in iCloud, but not sure how to do it. Please give kind help if anyone knows about this issue, or if anyone knows complete deletion step of Playground. Best wishes, tons of thanks in advance. Best Regards, Issey Hamada
Posted Last updated
.
Post not yet marked as solved
1 Replies
354 Views
I'm getting the following error when previewing my Swift Playground package: Unrecognized platform name 'xrOS'; did you mean 'iOS'? Anyone know how to silence this? I don't have xrOS anywhere in my code so I'm guessing this is something with Swift Playgrounds or with the compiler.
Posted
by kudit.
Last updated
.
Post not yet marked as solved
0 Replies
238 Views
I tried to use navigationstack, and it works. but couldn't print the path, and with the message: " NavigationPath(_items: SwiftUI.NavigationPath.(unknown context at $7ff84b690a28).Representation.eager([SwiftUI.(unknown context at $7ff84b6907f0).CodableItemBox<Swift.String>]), subsequentItems: [], iterationIndex: 0). " `import SwiftUI var toDos: [String] = [ "list1", "list2", "list3" ] struct ContentView: View { @State private var path = NavigationPath() var body: some View { NavigationStack(path: $path) { List { ForEach(toDos, id:\.self) { toDo in Button(action: { path.append(toDo) print(path) }, label: { Text("go to " + toDo) }) } } .navigationDestination(for: String.self) { toDo in Text("page for " + toDo) } } } } #Preview { ContentView() }` I tried navigationlink and simulator still works fine, but cannot print anything of path
Posted
by hyltlyy.
Last updated
.
Post not yet marked as solved
0 Replies
273 Views
Whenever we submit a new release to the App Store we get a nag email from Apple that states, "The app binary listed below was 199.2 MB when you submitted it, but will be 223.9 MB once processed for the App Store. This exceeds the cellular network download size limit and may require your app to be downloaded over Wi-Fi." However, when I download the app from the App Store and have the Settings set to "Alway Ask" on my phone the alert shows 129 MB, which is matches up closely with what we see in the TestFlight metadata for all device types except "Universal". What is "Universal" device type in these days of thinning? And why is Apple apparently using that number to generate the nag email?
Posted
by hotngui.
Last updated
.
Post not yet marked as solved
3 Replies
376 Views
Hi, I have submitted my playground for the Swift Student Challenge 2024. As in the competition guidelines it does not state that the app is going to be tested on a certain iPad Pro model- 12.9 or 11. However, my playground is only optimized for 12.9 as there are no specific rules on thee device it is being tested on. I have already submitted my playground so how will I inform the judges which iPad they have to test it on? Thanks :)
Posted Last updated
.
Post not yet marked as solved
2 Replies
312 Views
I have made a swift playground with the .playground extension but the WWDC24 Swift Student Challenge says I have to submit a .swiftpm file. What do I do to convert it to .swiftpm?
Posted Last updated
.
Post not yet marked as solved
1 Replies
344 Views
Hello, I’ve been trying to play system sounds in my app, but this hasn’t really been working. I am frequently switching between speech recognition (Speech framework) and sounds, so perhaps that’s where the issue lies. However, despite my best efforts, I haven't been able to solve the issue. I've been resetting the AVAudioSession category before playing a sound or starting speech recognition (as depicted in the code snippet below), to no avail. Has this happened to anyone else? Does anybody know how to fix the issue? recognizer = nil try? AVAudioSession.sharedInstance().setCategory(.playback, mode: .default, options: []) try? AVAudioSession.sharedInstance().setActive(true) AudioServicesPlaySystemSound(1113) try? AVAudioSession.sharedInstance().setCategory(.record, mode: .spokenAudio, options: []) try? AVAudioSession.sharedInstance().setActive(true) recognizer = SpeechRecognition(word: wordSheet) recognizer!.startRecognition() Thank you.
Posted Last updated
.
Post not yet marked as solved
1 Replies
382 Views
Hi, I'm using SwiftData in my app with the @available(iOS 17.0, *) annotation. It runs perfectly on iOS 17, but I encounter a weird memory error I can't seem to solve on iOS 16. Can I still submit my app, or will it be disqualified for not running on iOS 16? Thanks!
Posted
by mosafa1.
Last updated
.
Post not yet marked as solved
1 Replies
382 Views
How do I add a already made CoreML model into my playground? I tried what people recommended online -- building a test project and get the .mlmodelc file and put that in the playground along with the autogenerated class for the model. However, I keep on getting so many errors. The errors: Unexpected duplicate tasks Target 'help' (project 'help') has write command with output /Users/cpulipaka/Library/Developer/Xcode/DerivedData/help-appuguzbduqvojfwkaxtnqkozecv/Build/Intermediates.noindex/Previews/help/Intermediates.noindex/help.build/Debug-iphonesimulator/help.build/adc7818afdf4ae03fd98cdd618954541.sb Target 'help' (project 'help') has write command with output /Users/cpulipaka/Library/Developer/Xcode/DerivedData/help-appuguzbduqvojfwkaxtnqkozecv/Build/Intermediates.noindex/Previews/help/Intermediates.noindex/help.build/Debug-iphonesimulator/help.build/adc7818afdf4ae03fd98cdd618954541.sb Unexpected duplicate tasks Showing Recent Issues Target 'help' (project 'help'): CoreMLModelCompile /Users/cpulipaka/Library/Developer/Xcode/DerivedData/help-appuguzbduqvojfwkaxtnqkozecv/Build/Intermediates.noindex/Previews/help/Products/Debug-iphonesimulator/help.app/ /Users/cpulipaka/Desktop/help.swiftpm/Resources/ZooClassifier.mlmodel Target 'help' (project 'help'): CoreMLModelCompile /Users/cpulipaka/Library/Developer/Xcode/DerivedData/help-appuguzbduqvojfwkaxtnqkozecv/Build/Intermediates.noindex/Previews/help/Products/Debug-iphonesimulator/help.app/ /Users/cpulipaka/Desktop/help.swiftpm/Resources/ZooClassifier.mlmodel ZooClassifier.mlmodel: No predominant language detected. Set COREML_CODEGEN_LANGUAGE to preferred language.
Posted Last updated
.
Post not yet marked as solved
1 Replies
330 Views
Hello! For my Swift Student Challenge 2024 Project I'm using some Illustrations from OpenDoodles (opendoodles.com). Open doodles is free for commercial and personal use and the creator has no copyright claimed. My question is whether I have to clarify the use of these Illustration when submitting the project.
Posted
by Tiharz.
Last updated
.
Post not yet marked as solved
1 Replies
390 Views
Hi, I am trying to create a variable of type Color inside the swift data model in Xcode playground . This gives me these errors : No exact matches in call to instance method 'setValue' No exact matches in call to instance method 'getValue' No exact matches in call to instance method 'setValue' What is the problem?
Posted
by Shatha.
Last updated
.
Post not yet marked as solved
0 Replies
323 Views
Im making an app that uses drag&amp;drop but, it doesn't work. This is made with Swift Playground. If you can find a solution, please let me know. Here is the code. //MARK: Drop Area @ViewBuilder func DropAera()-&gt;some View{ VStack(spacing: 12){ ForEach($rows,id:\.self){$row in HStack(spacing: 10){ ForEach($row){$item in Text(item.value) .font(.system(size: item.fontSize)) .padding(.vertical,5) .padding(.horizontal,item.padding) .opacity(item.isShowing ? 1 : 0) .background{ RoundedRectangle(cornerRadius: 6, style: .continuous) .fill(item.isShowing ? .clear : .gray.opacity(0.25)) } .background{ // If Item is Dropped into Correct Plase RoundedRectangle(cornerRadius: 6, style: .continuous) .stroke(.gray) .opacity(item.isShowing ? 1 : 0) } // MARK: Adding Drop Operation // MARK: Adding Drag Drop Operation .onDrop(of: [.url], isTargeted: .constant(false)) { providers in if let first = providers.first{ let _ = first.loadObject(ofClass: URL.self) { value,error in guard let url = value else{return} if item.id == "\(url)"{ droppedCount += 1 let progress = (droppedCount / CGFloat(characters.count)) withAnimation{ item.isShowing = true updateShuffledArray(character: item) self.progress = progress } } else{ //Animating When Wrong text animateView() } } } return false } } } if rows.last != row{ Divider() } } } } @ViewBuilder func DragArea()-&gt;some View{ VStack(spacing: 12){ ForEach(shuffledRows,id: \.self){row in HStack(spacing: 10){ ForEach(row){item in Text(item.value) .font(.system(size: item.fontSize)) .padding(.vertical,5) .padding(.horizontal,item.padding) .background{ RoundedRectangle(cornerRadius: 6, style: .continuous) .stroke(.gray) } // MARK: Adding Drag Drop Operation .onDrag{ // Returning ID to find whitch Item is Moving return .init(contentsOf: URL(string: item.id))! } .opacity(item.isShowing ? 0 : 1) .background{ RoundedRectangle(cornerRadius: 6, style: .continuous) .fill(item.isShowing ? .gray.opacity(0.25) : .clear) } } } if shuffledRows.last != row{ Divider() } } } }
Posted
by Kazaki.
Last updated
.
Post not yet marked as solved
2 Replies
372 Views
I have a CollectionView in my SwiftUI App. The collectionView is wrapped in a UIViewRepresentable. If I tap on a collectionView cell normally the function isn't called but if I hold the cell down the console prints <0x107507790> Gesture: System gesture gate timed out. and when I let go of the cell after that's printed then didSelectItem is called. Here is my CollectionView Class: class SessionsCollectionView: UIView, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout { lazy var collectionView: UICollectionView = { let layout = UICollectionViewFlowLayout() layout.minimumInteritemSpacing = 0 layout.minimumLineSpacing = 30 let collectionView = UICollectionView(frame: CGRect.zero, collectionViewLayout: layout) collectionView.translatesAutoresizingMaskIntoConstraints = false collectionView.dataSource = self collectionView.delegate = self collectionView.clipsToBounds = false collectionView.delaysContentTouches = false collectionView.register(SessionCell.self, forCellWithReuseIdentifier: "cell") collectionView.register(SessionsHeader.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: "header") return collectionView }() override init(frame: CGRect) { super.init(frame: frame) self.backgroundColor = .clear setupCollectionView() } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } private func setupCollectionView() { addSubview(collectionView) collectionView.backgroundColor = .clear collectionView.alwaysBounceVertical = true collectionView.alwaysBounceHorizontal = false collectionView.delaysContentTouches = false collectionView.contentInset = .init(top: 20, left: 0, bottom: 20, right: 0) collectionView.showsVerticalScrollIndicator = false NSLayoutConstraint.activate([ collectionView.topAnchor.constraint(equalTo: topAnchor), collectionView.leadingAnchor.constraint(equalTo: leadingAnchor), collectionView.trailingAnchor.constraint(equalTo: trailingAnchor), collectionView.bottomAnchor.constraint(equalTo: bottomAnchor) ]) } // MARK: Header func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView { if kind == UICollectionView.elementKindSectionHeader { let sectionHeader = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "header", for: indexPath) as! Header return sectionHeader } } func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize { let width: CGFloat = collectionView.frame.width let height: CGFloat = 33 + 20 return CGSize(width: width, height: height) } // MARK: - UICollectionViewDataSource func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return 10 } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! SessionCell return cell } // MARK: - UICollectionViewDelegateFlowLayout func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { let width = collectionView.bounds.width let height = 150 return CGSize(width: collectionView.bounds.width, height: height) } func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { print(indexPath.row) } } struct SessionsCollectionViewWrapper: UIViewRepresentable { var sessionViewNavigation: SessionViewNavigation func makeUIView(context: Context) -> SessionsCollectionView { let sessionsCollectionView = SessionsCollectionView() return sessionsCollectionView } func updateUIView(_ uiView: SessionsCollectionView, context: Context) { // Update any properties or handle updates if needed } }
Posted Last updated
.