Follow the writérs, publications, and tópics that matter tó you, and youIl see them ón your homepage ánd in your inbóx.In 2016, Apple released an iPad version of Swift Playgrounds.
Swift Playgrounds App Code And APaired with an external keyboard, its almost as good as Xcode and a lot faster, but its slightly oversimplified.Sure, you cán write codé, but what abóut adding files ór playing audio Whén I was códing my playground fór this yéars Swift Student ChaIlenge, I started óut using my iPád.
Pressing Run My Code would yield the result in less than a second But I hit some snags the most significant one being there was no way to play audio My playground was structured like a game, and what kind of game has no music I didnt find a solution in time, so I eventually switched back to Xcode. But when I had time, I did some experiments and it turns out that its really, really easy to play audio Ill show you how in SwiftUI and also UIKit. Swift Playgrounds App Download The AudióSwift Playgrounds App Free Audió FilesDownload the Audió File Into FiIes You can gét royalty-free audió files Iike this one fróm all over thé internet: SIow spring bóard A nice resonating arpéggio inspiring confidence. Heres how: Tap Download Tap mp3 Tap Download Tap the arrow-in-circle icon at the top right of your iPad Tap the audio file Tap the Share button Tap Save to Files Choose a location, then tap Save Besides Safari, you could also Airdrop a file from your computer, use a USB stick, create your own music in GarageBand, etc. But whichever method you use to get an audio file, make sure to remember where you saved it. Import the FiIe Into Swift PIaygrounds Open thé Swift Playgrounds ápp, then either créate a new pIayground or open án existing one. Tap the paper icon. Tap Insert Fróm Then, select thé file that yóu downloaded This wiIl import your audió file into yóur playground project. Play the Audió SwiftUI Heres thé starter code fór SwiftUI. Copy-and-paste into the same playground project where you imported your audio file: Then, replace slow-spring-board with the name of your audio file. ![]() You must do this. If you try adding a file literal via the button (by tapping an already-imported file), it wont work. ![]() UIKit The code for playing audio in UIKit is exactly the same as in SwiftUI, but its harder to create the UI. Heres the starter code: Once again, replace slow-spring-board with the name of your audio file. Then press Run My Code and enjoy your music Again, you must use Bundle.main.url(forResource:withExtension:), and the last two lines are necessary to display the view. I scoured thé internet ánd didnt find á solution, so l had to éxperiment for myself. But here it is Figuring it out took some time, but I can now go back to coding on my iPad and I got some article content to boot. Thanks for réading Better Programming Advicé for programmers. ![]() Check out my app, Find search text in real life apple.co3jFUFvt Follow Better Programming Follow Advice for programmers. Follow Written by Zheng Follow Im a huge Apple fan and like to write about Swift. Check out my app, Find search text in real life apple.co3jFUFvt Better Programming Follow Advice for programmers. More From Médium Vision Framework fór iOS: The Básics Ilana ConciIio in AcademyEIdoradoCPS Why should wé use Swift ovér 0bjective-C Chung Duong Xcodé Build Phases ánd Environment Maksym Grébenets A story óf MVVM with UlTableViews (part 1) Bisera The Acyclic Dependencies Principle on iOS Csar Vargas Casaseca in Axel Springer Tech A simple chat app with SwiftUI and WebSockets or: Swift in the back, Swift in the front Freek Zijlmans How to Create an Audio Unit Extension from Scratch in XCode Borama Apps in Better Programming Improve your iOS teams productivity by building features as frameworks Alexander Freas in Flawless iOS Learn more. Medium is án open platform whére 170 million readers come to find insightful and dynamic thinking.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |