Skip to content

Instantly share code, notes, and snippets.

View lucianoschillagi's full-sized avatar
🛠️
Building

Luciano Schillagi lucianoschillagi

🛠️
Building
View GitHub Profile
@lucianoschillagi
lucianoschillagi / .swift
Created September 12, 2024 22:01
precondition method
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 == "😎",
@lucianoschillagi
lucianoschillagi / .swift
Created September 10, 2024 20:42
the sorted method example
import Foundation
class Person {
let name: String
let age: Int
init(name: String, age: Int) {
self.name = name
self.age = age
}
@lucianoschillagi
lucianoschillagi / .swift
Last active September 7, 2024 14:57
class-only protocols
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 {
@lucianoschillagi
lucianoschillagi / .swift
Created September 6, 2024 15:10
property observers example
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...
@lucianoschillagi
lucianoschillagi / .swift
Created September 2, 2024 23:54
Custom Implementations with Protocol Extensions
import Foundation
protocol Greetable {
var name: String { get }
func greet()
}
extension Greetable {
func greet() {
print("Hello, \(name)")
@lucianoschillagi
lucianoschillagi / .swift
Created August 27, 2024 15:45
Unicode Basic Emojies
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) {
@lucianoschillagi
lucianoschillagi / .swift
Created August 26, 2024 14:14
Unicode Scalars - Common Chinese 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
@lucianoschillagi
lucianoschillagi / .swift
Last active March 6, 2024 15:46
Swift @dynamicCallable attribute example
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."
}
@lucianoschillagi
lucianoschillagi / .swift
Last active February 15, 2024 15:53
Tuples with Pattern Matching in Swift
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)")
@lucianoschillagi
lucianoschillagi / .swift
Created December 19, 2023 11:21
Voice Over will read the Text "Hello Accesibility"
import SwiftUI
struct AccesibilityText: View {
var body: some View {
ZStack {
Color.mint.opacity(0.7).ignoresSafeArea()
VStack {
Text("Hello, Accessibility!")
.font(.largeTitle)