PhantomKit is a collection of many useful Swift and SwiftUI extensions and components. It is an invisible layer that supports your application and makes writing Swift code easier.
PhantomKit also uses the Xcore framework to import some useful extensions:
Date manipulation
Before
let nextMonth = Calendar.current.date(byAdding: .month, value: 1, to: Date())!
let isSameMonth = Calendar.current.compare(nextMonth, to: Date(), toGranularity: .month) == .orderedSame
After
let nextMonth = Date().adjusting(.month, by: 1)
let isSameMonth = Date().isSame(nextMonth, granularity: .month)
In-flight modifications with Appliable and MutableAppliable
Before
static let numberFormatter: NumberFormatter = {
let formatter = NumberFormatter()
formatter.locale = .init(identifier: "en_US_POSIX")
formatter.maximumFractionDigits = 3
return formatter
}()
extension PresentationMethod {
public enum Transition {
case link
case sheet
case fullScreen
}
}
extension PresentationMethod {
public enum Trigger {
case tap
case button(style: AnyButtonStyle)
case primitiveButton(style: AnyPrimitiveButtonStyle)
}
}
A custom LocalizedFormatter that automatically formats numbers, decimals and currencies for a specified locale:
extension LocalizedFormatter {
public static var currency = makeCurrencyFormatter(locale: .current, currencyCode: "USD")
public static var decimal = makeDecimalFormatter(locale: .current)
public static var percent = makePercentFormatter(locale: .current)
}
A custom LocalizedDateFormatter that automatically formats date and time for a specified locale:
extension LocalizedDateFormatter {
public static var date = makeDateFormatter(localizedFormat: "yyyyMMdd")
public static var datetime = makeDateFormatter(localizedFormat: "yyyyMMddjjmmss")
}
Examples:
let formatter = LocalizedDateFormatter.makeDateFormatter(locale: .init(identifier: "pl_PL"))
let date = Date(year: 2000, month: 3, day: 24)
expect(formatter.string(from: date)).to(equal("24.03.2000"))
let formatter = LocalizedDateFormatter.makeDateFormatter(
locale: .init(identifier: "en_US"),
localizedFormat: "yyyyMMddjjmmss"
)
let date = Date(year: 2000, month: 3, day: 24, hour: 16, minute: 14, second: 44)
expect(formatter.string(from: date)).to(equal("03/24/2000, 4:14:44 PM"))
PhantomKit
PhantomKit is a collection of many useful Swift and SwiftUI extensions and components. It is an invisible layer that supports your application and makes writing Swift code easier.
Requirements
Installation
Swift Package Manager
PhantomKit is available as a Swift Package.
Tip: to make PhantomKit truly invisible add the below line in the main file:
Highlights
Opening a NavigationLink on tap gesture
Natively
With PhantomKit
Executing an action before and after opening a NavigationLink
Opening a Web View
SwiftUI extensions
aligned
Before
After
expandingBackgroundColor
Before
After
Xcore extensions
PhantomKit also uses the Xcore framework to import some useful extensions:
Before
After
Appliable
andMutableAppliable
Before
After
and many more…!
Reference
Routing
Two enums for native SwiftUI routing:
View helpers:
Examples:
Formatting
LocalizedFormatter
A custom
LocalizedFormatter
that automatically formats numbers, decimals and currencies for a specified locale:Examples:
LocalizedDateFormatter
A custom
LocalizedDateFormatter
that automatically formats date and time for a specified locale:Examples:
Roadmap
Dependencies
PhantomKit uses the following frameworks:
License
PhantomKit is available under the MIT license. See the LICENSE file for more info.