https://github.com/jharsh1202/xylophone-ios
Musical instrument! A xylophone.
https://github.com/jharsh1202/xylophone-ios
apple-documentation avfoundation beginner ios ios-app ios-swift ios14 iosapp iosdevelopment swift swift4 swift5 uikit xylophone
Last synced: 2 months ago
JSON representation
Musical instrument! A xylophone.
- Host: GitHub
- URL: https://github.com/jharsh1202/xylophone-ios
- Owner: jharsh1202
- Created: 2021-05-15T17:25:05.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2021-06-22T04:18:06.000Z (almost 4 years ago)
- Last Synced: 2025-03-13T13:13:42.928Z (2 months ago)
- Topics: apple-documentation, avfoundation, beginner, ios, ios-app, ios-swift, ios14, iosapp, iosdevelopment, swift, swift4, swift5, uikit, xylophone
- Language: Swift
- Homepage:
- Size: 3.36 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Xylophone
## Our Goal
The goal of this tutorial is to dive into a simple iOS recipe - how to play sound and use an Apple library called AVFoundation.
## What you will create
You will be making your first musical instrument! A xylphone.
## What you will learn
* How to play sound using AVFoundation and AVAudioPlayer.
* Understand Apple documentation and how to use StackOverflow.
* Functions and methods in Swift.
* Data types.
* Swift loops.
* Variable scope.
* The ViewController lifecycle.
* Error handling in Swift.
* Code refactoring.
* Basic debugging.## Replacement Code
```
import UIKit
import AVFoundationclass ViewController: UIViewController {
var player: AVAudioPlayer!override func viewDidLoad() {
super.viewDidLoad()
}@IBAction func keyPressed(_ sender: UIButton) {
playSound()
}
func playSound() {
let url = Bundle.main.url(forResource: "C", withExtension: "wav")
player = try! AVAudioPlayer(contentsOf: url!)
player.play()
}
}
```# Xylophone