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 ContentView: View { | |
let url = URL(string: "https://dc4p.store")! | |
@State private var message = "Loading..." | |
var body: some View { | |
Text(message) | |
.task { |
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 ContentView: View { | |
// tracking changes of this property via 'onChange' method | |
@State private var notificationsEnabled = false | |
var body: some View { | |
Toggle("Notifications", isOn: $notificationsEnabled) | |
.padding() |
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 ContentView: View { | |
@State private var isSheetPresented: Bool = false | |
var body: some View { | |
VStack { | |
Button("Show Sheet") { | |
isSheetPresented = true | |
} |
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 | |
// Enumerations with Associated Values | |
enum OrderStatus { | |
case pending(orderID: Int, isAnOffer: Bool) | |
case shipped(orderID: Int, trackingNumber: String, isAnOffer: Bool) | |
case delivered(orderID: Int, date: String, signature: String?, isAnOffer: Bool) | |
} | |
// Usage examples |
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 | |
let beatles: Set<String> = ["John", "Paul", "George", "Ringo"] // unique values - hash value | |
for member in beatles { | |
print("'Beatle \(member)' has a hash value →", member.hashValue) | |
} | |
print("The Beatles was →", beatles.count) |
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 | |
struct Beatle { | |
let name = "George Harrison" | |
let instrument = "Guitar and Vocals" | |
let yearOfBorn = 1943 | |
let hisHitsSongs = ["Something", "Here comes the sun", "My Sweet Lord", "While My Guitar Gently Weeps"] | |
let wasAGreatMusician = true | |
} |
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 | |
enum Percentaje: String { | |
case ten = "◉ ○ ○ ○ ○ ○ ○ ○ ○ ○" | |
case twenty = "◉ ◉ ○ ○ ○ ○ ○ ○ ○ ○" | |
case thirty = "◉ ◉ ◉ ○ ○ ○ ○ ○ ○ ○" | |
case fourty = "◉ ◉ ◉ ◉ ○ ○ ○ ○ ○ ○" | |
case fifty = "◉ ◉ ◉ ◉ ◉ ○ ○ ○ ○ ○" | |
case sixty = "◉ ◉ ◉ ◉ ◉ ◉ ○ ○ ○ ○" | |
case seventy = "◉ ◉ ◉ ◉ ◉ ◉ ◉ ○ ○ ○" |
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 ContentView: View { | |
@Environment(\.myCustomValue) private var myCustomValue | |
var body: some View { | |
Text(myCustomValue).font(.title2) | |
} | |
} |
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 | |
// Converting JSON into data | |
let json = """ | |
{ | |
"name": "Dog", | |
"legs": 4 | |
} | |
""".data(using: .utf8)! |
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 | |
struct Cat { | |
// func saySomething() -> String { | |
// return "Muuu! I mean 'Miau!'" | |
// } | |
// Now, I am going to convert this method into a computed property | |
var saySomething: String { | |
return "Muuu! I mean 'Miau!'" |
NewerOlder