Swift Xylophone for iOS

Overview

App Brewery Banner

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. The most important skill of a great programmer is being able to solve your own problems. We’ll do that by exploring StackOverflow, Apple Documentation and learning how to search for solutions effectively. By learning to use these tools, you’ll be able to start adding custom features to an app and get it to do what you want it to.

What you will create

You will be making your first musical instrument! Music apps are so popular on the App Store that they even get their own category. So in this module, we’re going to make a colourful XyloPhone app. Get it? Ok, the jokes are bad, but remember, I only wrote the good ones...

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()
                
    }
}

This is a companion project to The App Brewery's Complete App Development Bootcamp, check out the full course at www.appbrewery.co

End Banner

You might also like...
Swift iOS coffee ordering app that uses the MVVM design pattern that makes
Swift iOS coffee ordering app that uses the MVVM design pattern that makes

CoffeeOrder Swift iOS coffee ordering app that uses the MVVM design pattern that makes "GET" and "POST" requests to an API for the orders Screenshots

Retos semanales de la comunidad MoureDev para practicar Swift & iOS
Retos semanales de la comunidad MoureDev para practicar Swift & iOS

Code Weekly Challenge Swift/iOS 2022 Proyecto de retos semanales de la comunidad MoureDev para practicar Swift e iOS. Existen repositorios de código t

Task App for Swift that Persist Data with Core Data (iOS)
Task App for Swift that Persist Data with Core Data (iOS)

Originally by: Michael Crump Updates for Xcode 10 with Swift 4.2 by David Phillip Oster

A listing app written in Swift for iOS.

Listr A listing app written in Swift for iOS. Listr is an app I developed following Mark Price's iOS 10 course. The idea is to list all the items/thin

Tipsy - Bill splitting and tip calculating App developed during iOS & Swift classes - The Complete App Development Bootcamp
Tipsy - Bill splitting and tip calculating App developed during iOS & Swift classes - The Complete App Development Bootcamp

Tipsy 💵 Bill splitting and tip calculating App developed during iOS & Swift cla

IOS Swift : Explain Higher-order Function Examples

IOS Swift : Explain Higher-order Function Examples

The source code of the EU Digital COVID Certificate App Core for iOS

This repository contains the source code of the EU Digital COVID Certificate App Core for iOS.

iOS App that browse the people from Star Wars Universe using GraphQL Api.
iOS App that browse the people from Star Wars Universe using GraphQL Api.

Ravn-Challenge-V2--OscarCastillo- iOS App that browse the people from Star Wars Universe using GraphQL Api. This project uses Apollo swift Client. htt

A simple iOS app with one default and four custom transitions.
A simple iOS app with one default and four custom transitions.

A simple iOS app with one default and four custom transitions. The app uses the same two view controllers for every transition.

Owner
null
Tech-Career-Growth-iOS - Official iOS app for the Tech Career Growth community

Developing the app Open the project from TCG.xcworkspace, not TCG.xcodeproj. It

Alexander Chiou 10 Feb 10, 2022
Scrumdinger-ios - Built as a part of iOS app dev tutorials from app-dev-training

Scrumdinger This repository contains the code written during my course of taking

Ashwin Ramakrishnan 1 Jan 23, 2022
IOS-Application-3 - A basic calculator app for iOS compatible to any layout and screen size

Calculator It is a basic calculator app for iOS compatible to any layout and scr

Kushal Shingote 1 Feb 2, 2022
iOS Blogging app with renewable subscriptions powered by RevenueCat; Written in Swift

Subscription Blogging App: Thoughts for iOS 1. Overview A modern blogging iOS app written in Swift with subscription paywalls powered by RevenueCat. T

Afraz Siddiqui 32 Dec 16, 2022
Full featured Spotify iOS Client written in Swift 5

Spotify Client (iOS - Swift 5 - 2021) Full featured Spotify like app written in Swift 5 with MVVM architecture. Features Official Spotify API Use Play

Anton Tuzov 3 Dec 8, 2022
A sample iOS app built using the Clean Swift architecture

Main Purpose is to create a simple project for Clean-Swift This project wrote with using Clean-Swift and MVP Design Pattern

Eyup Cimen 8 Oct 24, 2022
Example Xcode swift iOS project for Core Data + iCloud syncing

iCloudCoreDataStarter Hello, I'm Chad. For the last several months I have been working on Sticker Doodle, an app you should go download right now! In

Chad Etzel 521 Dec 27, 2022
Code Swift iOS app showcasing basic movies list from Orange TV API.

iOS Code Test - Optiva Media Code Swift iOS app showcasing basic movies list from Orange TV API. Built using XCode 13.0 (Swift 5) How to run the examp

Manu Martinez 1 Oct 17, 2021
Quizzler app for iOS using Swift

Quizzler Our Goal The goal of this tutorial is to take you one step further in your journey of becoming an app developer. We are going to introduce yo

null 0 Oct 31, 2021
Sample app to demonstrate the integration code and working of Dyte SDK for iOS, using Swift

docs-template by dyte ADD_DESCRIPTION_HERE Explore the docs » View Demo · Report Bug · Request Feature Table of Contents About the Project Built With

Dyte 8 Nov 26, 2021