Swiftpack.co - marchv/UIScreenExtension as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
marchv/UIScreenExtension 0.0.10
An extension to UIScreen that offers information about the pixel density (or point density) of iPhones and iPads.
⭐️ 55
🕓 2 weeks ago
.package(url: "https://github.com/marchv/UIScreenExtension.git", from: "0.0.10")


This is an extension to UIScreen that provides information about the pixel density (or point density) of iPhones and iPads. For example this can be used to:

  • compute the dimension of the screen

  • draw a ruler; or

  • to show a proper ECG graph on the iPhone's screen.

    public extension UIScreen {
      /// The number of pixels per inch for this device
      public static let pixelsPerInch: CGFloat?
      /// The number of pixels per centimeter for this device
      public static let pixelsPerCentimeter: CGFloat?
      /// The number of points per inch for this device
      public static let pointsPerInch: CGFloat?
      /// The number of points per centimeter for this device
      public static let pointsPerCentimeter: CGFloat?
      /// The screen dimension in inches
      public static let dimensionInInches: CGSize?
      /// The screen dimension in centimeters
      public static let dimensionInCentimeters: CGSize?

The constants will be set to .none if the device is unknown. This can happen if Apple releases a new iPhone, so please remember to deal with this in your code.

Installation and use

The extension can be installed using Swift Package Manager or Cocoapods by adding below line to your Podfile:

pod 'UIScreenExtension', :git => 'https://github.com/marchv/UIScreenExtension'

To use the extension in your code first import it by adding:

import UIScreenExtension

And then use it for example:

if let pointsPerCentimeter = UIScreen.pointsPerCentimeter {
   // code

Or to compute the diagonal screen dimension:

if let dimensionInInches = UIScreen.dimensionInInches {
    print(sqrt(pow(dimensionInInches.width, 2) + pow(dimensionInInches.height, 2))) // for example ~5.5 inches for iPhone 7 Plus


The extension supports all iPhones, iPods and iPads that are supported by iOS 9-14.


Please note that iPhone only apps upscaled on iPads will not work properly!


  • Apple Watch support
  • Objective C support
  • Fetch information about new iPhone models from internet





Stars: 55
Last commit: 2 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Submit a free job ad (while I'm testing this). The analytics numbers for this website are here.

Release Notes

Added iPhone 13
2 weeks ago

Added iPhone 13 and new iPads

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics