Skip to content
This repository was archived by the owner on Jul 20, 2025. It is now read-only.

Repository files navigation

X

VersionSwift VersionCarthage compatible

Easier cross platform Mac and iOS development with Swift 5.1. X was abstracted out of Redacted and Whiskey.

Xcode 11.1 or higher is required.

Installation

Carthage is the recommended way to install X. Add the following to your Cartfile:

github"soffes/X"

Usage

X provides several typealiases to make dealing with AppKit/UIKit types that are similar. Currently, X includes:

NameUIKitAppKit
ColorUIColorNSColor
ContentModeUIViewContentModeN/A
EdgeInsetsUIEdgeInsetsNSEdgeInsets
FontUIFontNSFont
GestureRecognizerStateTypeUIGestureRecognizerStateNSGestureRecognizerState
ImageUIImageNSImage
ScreenUIScreenNSScreen
ViewTypeUIViewNSView

If you wanted to use a color on both platforms, you could write something like this:

letblueColor=Color(red:0.298, green:0.757, blue:0.988, alpha:1.0)

View

View inherits from ViewType (so either UIView or NSView) and adds some platform specific functionality. This makes methods like layoutSubviews work on both platforms. The UIKit API is cleaner, so NSView has methods added in View to make it behave more like UIView.

Here's the current list of bridged methods that work on both:

varwantsLayer:Bool // On iOS, this doesn't do anything and always returns `true`.
func didMoveToWindow() // Bridged from `viewDidMoveToWindow`
func didMoveToSuperview() // Bridged from `didMoveToSuperview`
func layoutSubviews() // Bridged from `layout`

Core Graphics

There are several extensions for CGPoint, CGSize, and CGRect that help with converting to and from strings since UIKit and AppKit have different function names. The UIKit function names are aliased on Mac. There are also initializers and computed properties you can use instead of the functions.

Enjoy.

About

Easier cross platform Mac & iOS development with Swift

Topics

Resources

Stars

276 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages