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 XCTest | |
@testable import ReusingViewControllers | |
final class ReusableViewControllerTests: XCTestCase { | |
func test_lifeCycle_sendsEventsCorrectly() { | |
let (sut, delegateSpy) = makeSUT() | |
sut.viewDidLoad() | |
sut.viewWillAppear(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 UIKit | |
final class SceneDelegate: UIResponder, UIWindowSceneDelegate { | |
var window: UIWindow? | |
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { | |
guard let windowScene = (scene as? UIWindowScene) else { return } | |
let view = QuoteView() | |
let viewController = ReusableViewController(with: view) |
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
-- Set initial variables | |
set isWiFiConnected to false | |
set maxAttempts to 10 | |
set attemptCount to 0 | |
set wifiOffDelay to 0.1 -- Set the delay duration (in seconds) after turning Wi-Fi off | |
set connectionCheckDelay to 5 -- Set the delay duration (in seconds) before checking Wi-Fi connection status after turning Wi-Fi on | |
-- Repeat the loop until Wi-Fi is connected or the maximum number of attempts is reached | |
repeat while not isWiFiConnected and attemptCount < maxAttempts | |
-- Increment the attempt 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 UIKit | |
final class UIKitSampleView: UIView { | |
private let containerView = UIView() | |
private let titleLabel: UILabel = { | |
let label = UILabel() | |
label.text = "Hello, world!" | |
label.font = .preferredFont(forTextStyle: .largeTitle) | |
return label |
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 ViewKit | |
final class ViewKitSampleView: ProgrammaticView { | |
var body: UIView { | |
VerticalStack(spacing: 40) { | |
UILabel("Hello, world!") | |
.font(.preferredFont(forTextStyle: .largeTitle)) | |
UIButton("Tap me!") { _ in print("Tapped") } |
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 XCTest | |
extension XCTestCase { | |
func assertDeallocated( | |
_ instance: AnyObject, | |
file: StaticString = #filePath, | |
line: UInt = #line | |
) { | |
addTeardownBlock { [weak instance] in | |
XCTAssertNil( |
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 | |
private struct OnLoad: ViewModifier { | |
let action: () -> Void | |
@State private var loaded = false | |
func body(content: Content) -> some View { | |
content.onAppear { | |
if !loaded { | |
loaded = 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
extension MutableCollection { | |
subscript(safe index: Index) -> Element? { | |
get { | |
indices.contains(index) ? self[index] : nil | |
} | |
set { | |
if let newValue, indices.contains(index) { | |
self[index] = newValue | |
} |