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 Foundation | |
// Swift Standard Library - Exploring its methods! | |
// The 'precondition' method. | |
let faceWithSunglasses: Character = "🙂" | |
//let faceWithSunglasses: Character = "😎" | |
// if this precondition is not true, the program will be interrupted | |
precondition(faceWithSunglasses == "😎", |
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 Foundation | |
class Person { | |
let name: String | |
let age: Int | |
init(name: String, age: Int) { | |
self.name = name | |
self.age = age | |
} |
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 Foundation | |
// Define a class-only protocol conforming 'Vehicle' to 'AnyObject'. | |
protocol Vehicle: AnyObject { | |
var numberOfWheels: Int { get } | |
func drive() | |
} | |
// Define a class that adopts the protocol. | |
class Car: Vehicle { |
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 Cocoa | |
/// Property Observers 👀 | |
class Person { | |
var favoriteColor = "BLUE" { | |
// and now my 'favoriteColor' will be... | |
willSet(newFavoriteColor) { | |
print("My favorite color NOW is '\(newFavoriteColor)'") | |
} | |
// my 'favoriteColor' was... |
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 Foundation | |
protocol Greetable { | |
var name: String { get } | |
func greet() | |
} | |
extension Greetable { | |
func greet() { | |
print("Hello, \(name)") |
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 Cocoa | |
func printBasicEmojies() { | |
let startScalar = 0x1F600 | |
let endScalar = 0x1F64F | |
// Iterate over the range and print each character | |
for scalarValue in startScalar...endScalar { | |
if let scalar = UnicodeScalar(scalarValue) { |
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 Cocoa | |
func printCJKUnifiedIdeographs() { | |
// Define the range of Unicode scalars | |
// Examples: Common Chinese characters (e.g., 中, 国). | |
let startScalar = 0x4E00 | |
let endScalar = 0x9FFF | |
// Iterate over the range and print each character |
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 Foundation | |
@dynamicCallable | |
struct PersonIntroduceYourself { | |
func dynamicallyCall(withArguments names: [String]) -> String { | |
guard names.count == 2 else { | |
return "Invalid number of arguments. | |
Please provide both first name and last name." | |
} |
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 Cocoa | |
func processCoordinates(coordinates: (Double, Double)) { | |
switch coordinates { | |
case (0, 0): | |
print("You're at the origin!") | |
case (let x, 0): | |
print("You're on the x-axis at \(x)") | |
case (0, let y): | |
print("You're on the y-axis at \(y)") |
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 SwiftUI | |
struct AccesibilityText: View { | |
var body: some View { | |
ZStack { | |
Color.mint.opacity(0.7).ignoresSafeArea() | |
VStack { | |
Text("Hello, Accessibility!") | |
.font(.largeTitle) |
NewerOlder