Skip to content

Instantly share code, notes, and snippets.

View SwiftBeta's full-sized avatar
💻

SwiftBeta SwiftBeta

💻
View GitHub Profile
class DataModel {
let name: String
}
let dataModel = DataModel(name: "SwiftBeta")
struct DataModel {
let name: String
}
let dataModel = DataModel(name: "SwiftBeta")
let numbers = ["1", "2", "3"].map(Int.init)
print(numbers)
//Queremos transformar A en B, y para ello podemos usar una Higher Order Function en Swift
let A = [["1"], ["2", "3"], ["4"], ["5", "6", "7"]]
let B = ["1", "2", "3", "4", "5", "6", "7"]
let name: String? = "Suscríbete a SwiftBeta"
let type1: String? = "SwiftUI"
let type2: String? = "Swift"
let type3: String? = "Xcode"
let finalValue = name ?? type1 ?? type2 ?? type3
print(finalValue)
func printMessage() {
print("Message 1")
defer {
print("Message 2")
}
print("Message 3")
}
printMessage()
let data = """
{
"user": "SwiftBeta",
"subscriber": true
}
""".data(using: .utf8)!
struct User: Encodable {
let user: String
let subscriber: Bool
struct CharacterModel: Decodable {
let id: Int
let name: String
let image: String
let episode: [String]
let locationName: String
let locationURL: String
enum CodingKeys: String, CodingKey {
case id
@SwiftBeta
SwiftBeta / quiz_question_03_03_20230.swift
Created March 3, 2023 20:00
Snippet code SwiftBeta Quiz Questions
var str: String? = "Hello, world!"
print(str ?? "default")
@SwiftBeta
SwiftBeta / quiz_question_03_03_20231.swift
Created March 3, 2023 20:00
Snippet code SwiftBeta Quiz Questions
func sum(a: Int, b: Int) -> Int {
return a + b
}
let result = sum(a: 2, b: 3)
print(result)