A Swift Package which consists of a large amount of extensions & models for simplified and added functionality.
Easily convert between color formats, HSBA, RGBA, UIColor & CGColor. Also includes methods to increase brightness, interpolating color & higlighting
Simplify support dark/light mode:
static var backgroundColor: DynamicColor = .init(
.dark(RGBA(r255: 44, g255: 44, b255: 46)),
.light(.white))
view.backgroundColor = backgroundColor.uiColor()
Big help for creating calendar apps through a library of calendar structs with quite a lot of helper methods.
Easier to move between weeks, days & months:
var nextWeek = Day.today.week.nextWeek()
print("Next week is week: ", nextWeek.weekOfYear)
print("The year is: ", nextWeek.year)
Handling of timespans:
let swimmingEvent = Timespan(
from: .init(hour: 15, minute: 30),
to: .init(hour: 16, minute: 30))
let bowlingEvent = Timespan(
from: .init(hour: 16, minute: 0),
to: .init(hour: 16, minute: 30))
if swimmingEvent.isClipping(bowlingEvent) {
print("Events are overlapping")
}
Makes it quicker and easier to animate CALayer. All properties otherwise animatable through traditional methods are accessible through this approach.
// Animate Opacity
CALayer.animate(layer: view.layer, valueKey: \.opacity,
to: 0, duration: 0.4, option: .easeIn)
// Animate Corner Radius
CALayer.animate(layer: view.layer, valueKey: \.cornerRadius,
to: 10, duration: 0.3, option: .easeInQuad)
// Animate Background Color
let color = CGColor(gray: 1, alpha: 0)
CALayer.animate(layer: view.layer, valueKey: \.backgroundColor,
to: color, duration: 0.5, option: .easeInQuad)
// Animate Gradient
let gradientLayer = CAGradientLayer()
let newColors: [CGColor] = [.red, .green]
CALayer.animate(layer: gradientLayer, valueKey: \.colors,
to: newColors, duration: 1.2, option: .easeOut)
A large amount of enums which helps in making code easier to read & helps when dealing with math, axis, color profiles & graphics/design apps
Easier creation of scalable fonts & SF Fonts:
label.font = .display(ofSize: .largeTitle, weight: .bold)
label.font = UIFont(name: "Helvetica", size: 20).with(style: .caption1, maxPointSize: 15)
label.font = .rounded(ofSize: .heading, maxPointSize: 20)
label.font = .rounded(ofSize: 20, weight: .black)
Methods have for easier register & getter for UITableViewCell & UICollectionViewCell. No need to spesify identifier, identifier is automatically set to the name of the cellClass or headerClass
New:
Old:
// Register
collectionView.register(cell: CustomCollectionCell.self)
// Getter
func collectionView(_ collectionView: UICollectionView,
cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell: CustomCollectionCell = collectionView.dequeueReusableCell(for: indexPath)!
return cell
}
Helper methods for creating a delay for number of seconds. There is no difference between delay & sleep, only a matter of preference.
await Task.delay(seconds: 2)
await Task.sleep(seconds: 5)
Simplifiers, utility views & Subclasses of all UIKit views have been made which automatically sets translatesAutoresizingMaskIntoConstraints to false. Usefull when not using Storyboards.
Easier creation of SF Symbol and custom symbol UIImage´s.
Equivalent initalizers to the ones listed above exists for custom symbols. The initalizer for custom symbol instead starts with:
// Without Toolkit
let image = UIImage(systemName: "person.2.fill", withConfiguration: UIImage.SymbolConfiguration(pointSize: 14))
// With ToolKit
let image = UIImage(systemName: "person.2.fill", pointSize: 14)
Quickly convert image to text, quite useful when wanting to display emojis or other symbols on a UIImageView.
let emojiText = "🎉"
let emojiImage = emojiText.toImage()
Easier access and management of localizations. Easier transfer from swift localizations into other languages like javascript & typescript.
Safer & easier access:
// Old
let hello = NSLocalizedString("hello", comment: " ")
// New
let hello = Localizations.hello
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
String.printLocalizationsSwift()
...
import Foundation
import Toolkit
class Localizations {
static var acceptAndJoin: String {get {"acceptAndJoin".localized}}
static var admin: String {get {"admin".localized}}
static var cancel: String {get {"cancel".localized}}
static var `continue`: String {get {"`continue`".localized}}
static var createYourOwn: String {get {"createYourOwn".localized}}
static var dismiss: String {get {"dismiss".localized}}
...
// In the starter methods of SceneDelegate or AppDelegate
String.printLocalizationsJavascript()
Localizations can now in the Javascript application be accessed like below:
// Old
var invalidEmail = localize("invalidEmail")
// New
var invalidEmail = Localizations.invalidEmail
link |
Stars: 0 |
Last commit: 1 year ago |
Lots of new helpers & simplifiers
Full Changelog: https://github.com/Iliasnolsson/Toolkit/compare/1.0.0...1.0.1
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics