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
enum USState: String, CaseIterable { | |
case alabama = "AL" | |
case alaska = "AK" | |
case arizona = "AZ" | |
case arkansas = "AR" | |
case california = "CA" | |
case colorado = "CO" | |
case connecticut = "CT" | |
case delaware = "DE" | |
case florida = "FL" |
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
VStack { | |
HStack { | |
Text(log.name) | |
.lineLimit(lineLimit) // lineLimit is @State var | |
.foregroundColor(.black) | |
.multilineTextAlignment(.leading) | |
Spacer() | |
} | |
.padding(3) | |
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
class PropertyOwner { | |
var house: Home! | |
} | |
class Home { | |
var owner: PropertyOwner! | |
} | |
let home = Home() | |
let propertyOwner = PropertyOwner() |
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
class ListNode { | |
var value: Int | |
var next: ListNode? | |
init(_ val: Int) { | |
self.value = val | |
self.next = nil | |
} | |
} |
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
extension ListNode { | |
func forEach() { | |
var current: ListNode? = self | |
while current != nil { | |
print(current!.val) | |
current = current!.next | |
} | |
} |
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
private func assertNoMemoryLeak(_ instance: AnyObject, file: StaticString = #filePath, line: UInt = #line) { | |
addTeardownBlock { [weak instance] in | |
XCTAssertNil(instance, "Instance should have been deallocated. Potential retain cycle.", file: file, line: line) | |
} | |
} |
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 testRetainCycle() { | |
let vc = ViewController() | |
vc.countIt() | |
XCTAssertEqual(vc.numberOfTimes, 1) | |
assertNoMemoryLeak(vc, file: #filePath, line: #line) | |
} |
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 UIKit | |
class ViewController: UIViewController { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
detach { [weak self] in | |
await print(self?.getGoogle()) | |
} | |
} |
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 UIKit | |
class ViewController: UIViewController { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
detach { [weak self] in | |
do { | |
try await print(self?.getKennyDubroff()) | |
} catch { |
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 UIKit | |
class TitledCollectionView: UIView { | |
private lazy var vStack: UIStackView = { | |
let stack = UIStackView(arrangedSubviews: [titleLabel, collectionView]) | |
stack.translatesAutoresizingMaskIntoConstraints = false | |
stack.axis = .vertical | |
stack.distribution = .fill | |
stack.alignment = .fill |