Skip to content

Instantly share code, notes, and snippets.

View SURYAKANTSHARMA's full-sized avatar
🎯
Focusing

Suryakant SURYAKANTSHARMA

🎯
Focusing
View GitHub Profile
@propertyWrapper struct Currency {
var projectedValue: Bool
// This is must stored property in every property wrapper
var wrappedValue: String {
didSet {
wrappedValue = "₹ " + wrappedValue
projectedValue = wrappedValue.contains(",")
}
class Singleton {
private init() { }
static let sharedInstance: Singleton = {
let instance = Singleton()
// setup code
return instance
}()
}
typealias CGFloat = (Float, Float)
class UIResponder {
func handleTap(event: TapEvent) {}
}
class TapEvent {
let location: CGFloat
init(location: CGFloat) {
class Singleton {
private init() { }
static let sharedInstance = Singleton()
}
class MockURLOpener: URLOpening {
var openedURL: URL?
func open(_ url: URL,
options: [UIApplication.OpenExternalURLOptionsKey : Any],
completionHandler: ((Bool) -> Void)?) {
openedURL = url
}
}
func testDocumentOpener() {
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)?)
}
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)"
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)
}
typealias Price = Double
struct Product {
let name: String
let price: Price
}
struct Coupon {
let code: String
let percentage: Double
}
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")
}
}