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
@propertyWrapper struct Currency { | |
var projectedValue: Bool | |
// This is must stored property in every property wrapper | |
var wrappedValue: String { | |
didSet { | |
wrappedValue = "₹ " + wrappedValue | |
projectedValue = wrappedValue.contains(",") | |
} |
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
class Singleton { | |
private init() { } | |
static let sharedInstance: Singleton = { | |
let instance = Singleton() | |
// setup code | |
return instance | |
}() | |
} |
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
typealias CGFloat = (Float, Float) | |
class UIResponder { | |
func handleTap(event: TapEvent) {} | |
} | |
class TapEvent { | |
let location: CGFloat | |
init(location: CGFloat) { |
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
class Singleton { | |
private init() { } | |
static let sharedInstance = Singleton() | |
} |
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
class MockURLOpener: URLOpening { | |
var openedURL: URL? | |
func open(_ url: URL, | |
options: [UIApplication.OpenExternalURLOptionsKey : Any], | |
completionHandler: ((Bool) -> Void)?) { | |
openedURL = url | |
} | |
} | |
func testDocumentOpener() { |
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
struct Document { | |
let identifier: Int | |
} | |
enum Mode: String { | |
case edit = "edit" | |
case view = "view" | |
} | |
protocol URLOpening { | |
func open(_ url: URL, options: [UIApplication.OpenExternalURLOptionsKey : Any], completionHandler completion: ((Bool) -> Void)?) | |
} |
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
struct Document { | |
let identifier: Int | |
} | |
enum Mode: String { | |
case edit = "edit" | |
case view = "view" | |
} | |
class DocumentOpener { | |
func openUrl(document: Document, mode: Mode) { | |
let stringURL = "myappscheme://open?id=\(document.identifier)&mode=\(mode.rawValue)" |
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
func testCart() { | |
let product = Product(name: "Macbook", price: 100) | |
var cart = Cart() | |
cart.products.append(product) | |
XCTAssertEqual(product.price, cart.totalPrice) | |
let coupon = Coupon(code: "SPECIAL20", percentage: 20) | |
cart.apply(coupon) | |
XCTAssertEqual(cart.totalPrice, 80) | |
} |
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
typealias Price = Double | |
struct Product { | |
let name: String | |
let price: Price | |
} | |
struct Coupon { | |
let code: String | |
let percentage: Double | |
} |
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
func testAppraisal() { | |
let user = User(name: "John", salary: 100.0) | |
let result = Appraisal(user: user, rating: PerformanceRating.exceedExpection).perform() | |
switch result { | |
case .bonus(let amount): | |
XCTAssertTrue(amount == 200.0) | |
default: | |
XCTFail("Appraisal Perform function is faulty") | |
} | |
} |
NewerOlder