Created
August 10, 2016 14:58
-
-
Save maxcampolo/be7db6b96e628e47083c070dd91044dd to your computer and use it in GitHub Desktop.
Global constants with swift extensions and Implicit Member Expression.
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
extension Double { | |
public static let kRectX = 30.0 | |
public static let kRectY = 30.0 | |
public static let kRectWidth = 30.0 | |
public static let kRectHeight = 30.0 | |
} | |
public func makeRect() -> CGRect { | |
return CGRect(x: .kRectX, y: .kRectY, width: .kRectWidth, height: .kRectHeight) | |
} | |
extension String { | |
// Notifications | |
public static let myCustomNotification = "myCustomNotification" | |
// URL paths | |
public static let myURLPath = "https://www.google.com/" | |
public static func myOtherURLPath() -> String { return "https://www.google.com" } | |
} | |
extension NSURL { | |
public static let myURL = NSURL(string: .myURLPath) | |
public static let myOtherURL = NSURL(string: .myOtherURLPath()) | |
public static func myThirdURL() -> NSURL { return NSURL(string: .myURLPath)! } | |
} | |
public func postNotification () { | |
NSNotificationCenter.defaultCenter().postNotificationName(.myCustomNotification, object: nil) | |
} | |
public func makeRequest() { | |
// Can't omit type with just string | |
let request = NSMutableURLRequest(URL: NSURL.myURL!) | |
let otherReqeust = NSMutableURLRequest(URL: NSURL.myOtherURL!) | |
// Can omit with func! | |
let thirdRequest = NSMutableURLRequest(URL: .myThirdURL()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment