We’re all aware that global variables are bad and that we shouldn’t do globals. Right? Well... Sometimes you need globally available information like user interface idiom or OS version. This information is available from UIDevice and you can grab it from anywhere in your app. Testing Device Idiom and OS Version in Swift if UIDevice.currentDevice().userInterfaceIdiom == UIUserInterfaceIdiom.Phone { ... } if UIDevice.currentDevice().systemVersion.compare("8.0", options: NSStringCompareOptions.NumericSearch) != NSComparisonResult.OrderedAscending { ... } However, that’s a lot type type and isn’t easy to read either. In Objective-C we could use macros in the pre-compiled header to make application code easier to read and write.
A developer's blog who codes on Java, PHP, .NET (C#) , Swift and Python. Articles, tips and tricks, tutorials and news on major programming languages and development tools.