how to make extension for optional in swift
extension Swift.Optional where Wrapped == String {
var isBlank: Bool {
return self?.isBlank ?? true
}
}
how to make extension for optional in swift
extension Swift.Optional where Wrapped == String {
var isBlank: Bool {
return self?.isBlank ?? true
}
}
extension swift
// A basic class
class MyClass {
private let a = 5
func getA() -> Int {
return self.a
}
}
// An extension of that class - adds a function
extension MyClass {
// Add an amount to the value of `a`
func add(_ amount: Int) -> Int {
// self can be used to access MyClass' members
return self.getA() + amount
}
}
var mc = MyClass()
print(mc.getA()) // Direct member of the class (Output: 5)
// Function from extension - called as if the function
// was in the original definition. (Output: 10)
print(mc.add(5))
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us