[swift-evolution] Proposal : Introduction of System Defined UI Variables - ScreenSize, IsPad.

Tarun Tyagi taruntyagi697 at gmail.com
Thu Dec 3 20:34:30 CST 2015

Hi Guys

I would like to propose a small addition. Please have a look at following and let me know your thoughts -

Proposal : Introduction of System Defined UI Variables - ScreenSize, IsPad.

Motivation : All of us know that we have a pretty good set of methods that can provide us this information. UIScreen is there to provide this. But when the app supports autorotation, in landscape, it's width becomes height and vice-versa, leaving developer to figure out what the current width and height is.
This forces developer to write some lines of unnecessary code every time an app starts supporting autorotation. If we had system defined variables, we could easily rely on them, regardless of current orientation.

Use Case : When app receives an autorotation event, we need to perform changes to our UI accordingly where it needs these ScreenSize(updated) & IsPad variables.

Note : Everybody is aware that -
Autolayout takes care of the most issues down this line.
Calculations(on mere change of orientation) are rarely needed when you correctly use Autolayout.

But we can never rule out the possibility. A system defined variable comes to quick rescue.

Does it go along Swift's Evolution?
Obviously, a short and smart addition to developer toolkit.

Does it break any existing code?
Absolutely No.

Advantages : A lot of unnecessary code can be abstracted from user providing a clean interface that facilitates the needed info (updated to current orientation) using a reliable system variable.

Has it been considered before?
Yes, revised autorotation approach (Adaptive)

func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator)

is a place to look at. Yes, it specifically handles the use case that I described above. But does it eliminate the need of ScreenSize? Not Completely.

It gets along with a super smart language Swift's evolution direction and should be welcomed by most of the developers.

Let me know your thoughts.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151204/8f2db525/attachment.html>

More information about the swift-evolution mailing list