The next update (index 1.8.0
version number index) will bring the following changes, extensions and custom types:
CoreImage
Inverts the colors of self
:
let invertedImage = ciImage.inverted
// invertedImage holds the same image data but with inverted colors
Generates a QR image from the input text
and with an optional scale
parameter that specifies the affine transformation for the output CIImage
:
let helloWorldQRImage = CIImage.qrImage(from: "Hello World!")
// helloWorldQRImage holds image data that represents QR code for `Hello World!` message
Applies the specified color
as a tint color:
let redQRImage = qrImage.tinted(by: .red)
// redQRImage holds the same QR image data as before but tinted by red color
A number of extensions that convert the target CIImage
instance to it's transparent version by applying alpha masking filter:
let transparentImage = ciImage.transparent
let blackTransparentImage = anotherImage.blackTransparent
Foundation
NotificationCenter
Various utility extensions that help to reduce the boilerplate code:
NotificationCenter.post(notification: .userHasUpdated)
OperationQueue
Utility extensions for .main
operation queue:
OperationQueue.isMain // if current operation queue is the main the result will be true, otherwise false
OperationQueue.onMain {
// This closure will be executed on the main operation queue
}
NSObjectProtocol
Observe and bind observables with ease:
// Binding is as easy as writing just a single line of code:
viewModel.bind(\.progressSlider, to: progressSlider, at: \.value)
// Observing for changes is thinner than the `Swifts 4.0` updated `KVO`:
viewModel.observe(\.buttonTitle) { [button] in
button!.setTitle($0, for: .normal)
}
Custom TextOutputStream
Prints the output stream to the specified file for the given URL
and encoding
:
let url = URL(fileURLWithPath: "/somePath/subpath/file.rtf")
let fileHandle = try FileHandle(forWritingTo: url)
var textOutputStream = TextOutputStream(fileHandle)
print("\(outputString)", &textOutputStream)
// The print statement will write the output stream to the specified FileHandle at the specified URL. This stream mimics Java's SDK File Output Stream.
Prints all the Unicode
characters with the following scheme:
var unicodeOutputStream = UnicodeOutputStream()
print("👨👩👧👧", to: &unicodeOutputStream)
// Will print all the unicode indices + characters + names
NSObject
Decodable
Custom Structures
- Variable - lightweight bindable data type that allows to get on update notifications for a given value. Can be used with
MVVM
or any another architectural pattern to replace the need for 3rd party, heavyweight binding framework.
Sequence
Date Structured
- BuilderProtocol - Allows
AnyObject
to be extended with chainable initialization methods by using Keypath feature. Please note that the extension works only since Swift 4.0
String
- String+Subscript - adds conformances to
CoutableClosedRange
, CountableRange
, PartialRangeThrough
and PartialRangeFrom
protocols support in a form of subscripts
Custom Protocols
The protocol supposed to be used with types that need identification, such as UITableViewCell, UITableViewHeaderFooterView, UICollectionReusableView etc.:
class FeedTableViewCell: UITableViewCell, Identifiable {
// ...
// Implementation details
// ...
}
// Somewhere in `UITableViewControllerDelegate`:
let cell = dequeueReusableCell(withIdetifier: cell. reuseIdentifier)
Protocol for object configuration:
var imageView = UIImageView().then {
$0.layer.cornerRadius = 10
$0.contentMode = .scaleAspectFill
$0.clipsToBounds = true
}
Custom Type
Allows an action to be performed after a delay:
let debouncer = Debouncer(delay: 2.0)
debouncer.schedule {
value = "Changed Value"
}
// After 2.0 seconds the value will be changed to "Changed Value"
Syncronous, thread-safe observable array type:
let array: ObservableArray = [1,2,3,4,5]
array += 6
array += [7,8]
array.allChanges = { change in
// Both changes will, for addition of `6` and `[7,8]` will be reflected in `change` property and the appropriate callbacks will be made
}
array.removeFirst()
array.removeLast()
array.remove(at: 4)
URL
Creates a QR image from the absoluteString
of the URL
:
let customUrlQRImage = url.qrImage()
// customUrlQRImage holds image data for QR image that represents the given URL address
UIKit
UIWindow
Syntactic sugar for much easier UIWindow
instantiation:
window = UIWindow.create(with: coordinator.rootViewController, option: .keyAndVisible)
UIView
UIView+Masking - masks the view with the specified UIRectCorner array and corner radius
UIAlertController
UIAlertController+Presentation - presents a UIAlertController with the given title, message, tintColor and alert actions
UIViewController
Loads, adds and removes container view controllers as children
UIViewController+Storyboard - implemented server new utility methods that help to more easily instantiate controllers from Storyboard
file. Also some improvements have been made to the existing API
Badge
Badge - a custom type, wrapper
badge app icon API
that simplifies development
UIImage
Downsamples the input image to the specified point size and scale factor. Can be used to present the thumbnails, supports caching:
UIColor
Blends two colors by mixing the RGBA
components:
let blendedColor = red.blend(with: blue, intensity: 0.5)
Changes the brightness of a color:
let brighterRed = red.increaseBrightness(0.25)
os
OSLog
Adds a number of convenient log levels and a global function that simplifies logging:
os_log("Received .json data from the remove", log: .network)
os_log("Attempting to sync with the main UI thread", log: .ui)
SceneKit
The extension adds a new action method that allows a node to move along a UIBezierPath
:
let flyoverAction = SCNAction.moveAlong(path: flyoverPath, z: 10, speed: plane.speed)
plane.run(flyoverAction)
Other improvements
The update brings the refaced documentation, more test coverage and removed docs
badge. Also TravisCI
and Codecov
were added.