I know the difference between private and fileprivate.
But what is the difference between
fileprivate extension UIStoryBoard { }
and
extension UIStoryBoard { }
The result of trying to write maintainable, clean code:
func fetchNumbersFromServer(completion: @escaping (NumbersResult) -> Void) {
let urlString = "https://some-site.com/some-file"
var request = URLRequest(url: URL.init(string:…
I have the following piece of code, the protocol MyDisplayable has three optional Strings, and I have a default implementation of the protocol via extension. My question is, since I'm sure the extension returns the three strings, is there a way I…
I have an extension class, where I'm extending UIButton like below, it's working fine.
extension UIButton {
class func backButtonTarget(_ target: Any, action: Selector) -> UIBarButtonItem {
let backButton = UIButton(frame:…
I have written an extension to resize a given image:
extension NSImage {
func resizeImage(width: CGFloat, _ height: CGFloat) -> NSImage {
let img = NSImage(size: CGSize(width:width, height:height))
img.lockFocus()
let…
I have extended the following protocol with a default parameter.
protocol XDelegate {
func close(response: Bool, status: Status)
}
extension XDelegate{
func close(response: Bool, status: Status = .UNDEFINED){}
}
whenever I call…
Here's my code right now:
@objc protocol BaseView {
@objc optional var header: UILabel { get set }
@objc optional var footer: UILabel { get set }
}
class ViewWithHeader: UIView, BaseView {
@IBOutlet var header: UILabel!
}
class…
I have a situation where I want to be able to use an existing field from a class to satisfy an extension to the class that specifies a protocol. Something like this:
class SomeThing {
var foo: String
}
protocol MyProtocol {
var foo: String…
I was storing couple of UIColors inside an array and changed my code to get them as a return value of a function as an UIColor extension.
Array version:
var colors : [UIColor] = [UIColor(red:0.35, green:0.40, blue:0.45, alpha:1.00),…
I'm writing an extension by taking a swift file and did codes in following way:
import Foundation
import UIKit
extension UIButton{
func backButtonTarget(_ target: Any, action: Selector) -> UIBarButtonItem {
let backButton =…
A playground contains only an extension of NSDecimalNumber that conforms it to ExpressibleByStringLiteral and a variable x that attempts to utilize that extension, and the LLDB RPC server crashes:
import Cocoa
extension NSDecimalNumber:…
I'm writing some extension methods for swift Array type.
The environment is Xcode8.3(8E162) and Swift3.1
I want to make the final code look like [1, 2, 3].cc.find { $0 < 2 } Here cc is like rx in RxSwift and snp in SnapKit.
To achieve that, I…
I want to create a protocol and extension which I will use in three different view controllers for API loading.
protocol WebAPILoader {
// URL of remote resource
var url: URL? { get set }
// Array supposed to store loaded data.
…
I'm thinking of defining:
extension UIViewController {
override var prefersStatusBarHidden: Bool {
return true
}
}
Does this also work for subclasses, like:
class UINavigationController: UIViewController {
override var…