This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
struct PhotoInfo: Codable { | |
var title: String | |
var description: String | |
var url: URL | |
var copyright: String? | |
enum CodingKeys: String, CodingKey { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
let urlString = "https://api.nasa.gov/planetary/apod" | |
var urlComponents = URLComponents(string: urlString)! | |
urlComponents.queryItems = [ | |
"api_key": "DEMO_KEY", | |
"date": "2022-04-11" | |
].map { URLQueryItem(name: $0.key, value: $0.value) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
//let urlString = "https://www.thecodehub.ie/v1/api.json" | |
let urlString = "https://api.nasa.gov/planetary/apod"//?api_key=DEMO_KEY" | |
let url = URL(string:urlString)! | |
var urlComponents = URLComponents(string: urlString)! | |
urlComponents.queryItems = [ | |
"api_key": "DEMO_KEY", | |
"date": "2022-04-11" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import NaturalLanguage | |
let greeting = "Hello, playground" | |
let inverno = "In questo libro lo si farà in maniera chiara, precisa e, per quanto possibile, divertente." | |
let don = "Y luego, en el margen, citar a Horacio, o a quien lo dijo." | |
let riverrun = "a way a lone a last a loved a long the riverrun, past Eve and Adam's, from swerve of shore to bend of bay, brings us by a commodious vicus of recirculation back to Howth Castle and Environs." | |
let texts = [inverno, don, riverrun] | |
func identifyLanguageOf(text: String) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension String { | |
var image: UIImage? { | |
// Change these values if you want (or need) an image larger than 100x100 | |
let size = CGSize(width: 100, height: 100) | |
UIGraphicsBeginImageContextWithOptions(size, false, 0) | |
// Maybe make this respect whether the user has selected light or dark mode... | |
// but we can also use UIColor.clear... | |
UIColor.clear.set() | |
let rect = CGRect(origin: .zero, size: size) | |
UIRectFill(CGRect(origin: .zero, size: size)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This code is for the Advice from the Lizard main.swift file | |
// It uses the playInstrument function to play an A4 with an electric guitar. | |
func performance(owner: Assessable) { | |
// TODO: Play an instrument using the calls the Lizard told you about | |
playInstrument(.electricGuitar, note: MIDINotes.a4) | |
// Let the Lizard know when you're done | |
owner.endPerformance() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let notes: [Note] = [Note.quarter(.a4), Note.quarter(.b4), Note.quarter(.c3)] | |
let toneOutput = ToneOutput() | |
var noteIndex = 0 | |
Timer.scheduledTimer(withTimeInterval: 0.4, repeats: true) { timer in | |
guard noteIndex < notes.count else { | |
toneOutput.stopTones() | |
timer.invalidate() | |
return | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Music.swift | |
// | |
// Copyright © 2020 Apple Inc. All rights reserved. | |
// | |
public protocol PitchProtocol { | |
/// The sonic frequency of this Pitch | |
var frequency: Double { get } |