This file contains hidden or 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
| public class UserDefaultsHelper { | |
| /// Use this generic func to encode and save an Codable object to UserDefaults | |
| /// - Parameters: | |
| /// - value: Any Codable type | |
| /// - key: The corresponding key | |
| /// - Returns: true if it is saved successfully, else false | |
| @discardableResult | |
| public static func save<T: Codable>(customValue value: T, withKey key: String) -> Bool { | |
| if let encoded = try? JSONEncoder().encode(value) { |
This file contains hidden or 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 | |
| public enum LoggerLevel { | |
| case info | |
| case debug | |
| case warning | |
| case error | |
| } | |
| final class Logger { |
This file contains hidden or 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 | |
| public final class UserDefaultsHelper { | |
| /// Use this generic func to encode and save an Codable object to UserDefaults | |
| /// - Parameters: | |
| /// - value: Any Codable type | |
| /// - key: The corresponding key | |
| /// - Returns: true if it is saved successfully, else false | |
| @discardableResult |
This file contains hidden or 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
| var body: some View { | |
| Text("She sells sea shells on the sea shore. She sells sea shells on the sea shore") | |
| .truncationMode(.head) | |
| } |
This file contains hidden or 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
| //1 | |
| let image = UIImage(named: "swifty")! | |
| let swifty = Bird(name: "Swifty", rarity: .veryRare, image: image) | |
| //2 | |
| let viewModel = BirdViewModel(bird: swifty) | |
| //3 | |
| let frame = CGRect(x: 0, y: 0, width: 300, height: 450) | |
| let view = BirdView(frame: frame) |
This file contains hidden or 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
| // MARK: - View | |
| public class BirdView: UIView { | |
| public let imageView: UIImageView | |
| public let nameLabel: UILabel | |
| public let purchaseFeeLabel: UILabel | |
| public override init(frame: CGRect) { | |
| var imageViewFrame = CGRect(x: 0, y: 16, width: frame.width, height: frame.width/2) | |
| imageView = UIImageView(frame: imageViewFrame) |
This file contains hidden or 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
| // MARK: - Bird View Model | |
| public class BirdViewModel { | |
| //1 | |
| private let bird: Bird | |
| public init(bird: Bird) { | |
| self.bird = bird | |
| } |
This file contains hidden or 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 PlaygroundSupport | |
| import UIKit | |
| public class Bird { | |
| public enum Rarity { | |
| case common | |
| case uncommon | |
| case rare | |
| case veryRare | |
| } |
This file contains hidden or 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
| func displayContent(urlString: String) -> Void { | |
| guard let url = URL(string: urlString) else{return} | |
| let hideScriptURL = Bundle.main.path(forResource: "hideSections", ofType: "js") | |
| do{ | |
| //Remove Content Blocks | |
| let scriptContent = try String(contentsOfFile: hideScriptURL!, encoding: String.Encoding.utf8) | |
| let hideSectionsScript = WKUserScript(source: scriptContent, injectionTime: .atDocumentStart, forMainFrameOnly: true) | |
| let controller = WKUserContentController() | |
| controller.addUserScript(hideSectionsScript) | |
| let config = WKWebViewConfiguration() |
NewerOlder