An open API service indexing awesome lists of open source software.

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.

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 AVFoundation

class 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