View List-Custom-Cell-IB-02.swift
struct SFSymbolNameContentConfiguration: UIContentConfiguration, Hashable { | |
var name: String? | |
func makeContentView() -> UIView & UIContentView { | |
// Initialize an instance of SFSymbolNameContentView | |
return SFSymbolNameContentView(configuration: self) | |
} | |
func updated(for state: UIConfigurationState) -> Self { |
View Google-Sign-In-Integration-11.swift
import UIKit | |
import GoogleSignIn | |
class ViewController: UIViewController { | |
var signInButton: UIButton! | |
var signOutButton: UIButton! | |
var greetingLabel: UILabel! | |
override func viewDidLoad() { |
View Google-Sign-In-Integration-04.swift
import UIKit | |
import GoogleSignIn | |
@UIApplicationMain | |
class AppDelegate: UIResponder, UIApplicationDelegate { | |
func application(_ application: UIApplication, | |
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { | |
// Initialize Google sign-in |
View Decode-Dynamic-Keys-JSON-Final.swift
let jsonString = """ | |
{ | |
"S001": { | |
"firstName": "Tony", | |
"lastName": "Stark" | |
}, | |
"S002": { | |
"firstName": "Peter", | |
"lastName": "Parker" | |
}, |
View Property-Wrapper-AppData-Full.swift
struct User: Codable { | |
var firstName: String | |
var lastName: String | |
var lastLogin: Date? | |
} | |
@propertyWrapper | |
struct Storage<T: Codable> { | |
private let key: String | |
private let defaultValue: T |
View Property-Wrapper-AppData-2.swift
struct AppData { | |
@Storage(key: "enable_auto_login_key", defaultValue: false) | |
static var enableAutoLogin: Bool | |
@Storage(key: "username_key", defaultValue: "") | |
static var username: String | |
} |
View Property-Wrapper-AppData-1.swift
struct AppData { | |
private static let enableAutoLoginKey = "enable_auto_login_key" | |
private static let usernameKey = "username_key" | |
static var enableAutoLogin: Bool { | |
get { | |
// Read from UserDefaults | |
return UserDefaults.standard.bool(forKey:enableAutoLoginKey) | |
} |
View Optional-Operator-4.swift
class Boy { | |
// Failable initialisation | |
init?(age: Int) { | |
// Age cannot be less than 0 | |
if age < 0 { | |
return nil | |
} | |
} | |
} |
View Optional-Operator-3.swift
let str: String? = "test" | |
// Optional binding using 'if' | |
if let value = str { | |
print(value) | |
} | |
// Optional binding using guard | |
guard let value = str else { |
View Optional-Operator-2.swift
// Create another bird array that accept nil value | |
let otherBirds: [Bird?] = [chicken, nil] | |
let chicken4 = otherBirds[0] as? Chicken? // Cast successful: chicken4 type is Chicken?? | |
let chicken5 = otherBirds[0] as! Chicken? // Cast successful: chicken5 type is Chicken? | |
let chicken6 = otherBirds[1] as? Chicken? // Cast failed: Trigger runtime error | |
let chicken7 = otherBirds[1] as! Chicken? // Cast failed: Trigger runtime error | |
let chicken8 = otherBirds[0] as? Chicken! // chicken8 type is Chicken?? | Warning: Using '!' here is deprecated and will be removed in a future release | |
let chicken9 = otherBirds[0] as! Chicken! // chicken9 type is Chicken? | Warning: Using '!' here is deprecated and will be removed in a future release |
NewerOlder