Giter Club home page Giter Club logo

extensions-kit's Introduction

extensions-kit Awesome

Build Platforms Language SPM Extensions CustomTypes NLOC License

Last Update: 22/April/2022.

If you like the project, please give it a star ⭐ It will show the creator your appreciation and help others to discover the repo.

✍️ About

📦 Collection of Swift extensions(+ custom types) for various use cases.

🏗 Installation

Swift Package Manager

Xcode 11+

  1. Open MenuBarFileSwift PackagesAdd Package Dependency...
  2. Paste the package repository url https://github.com/jVirus/extensions-kit and hit Next.
  3. Select the installment rules.

After specifying which version do you want to install, the package will be downloaded and attached to your project.

Package.swift

If you already have a Package.swift or you are building your own package simply add a new dependency:

dependencies: [
    .package(url: "https://github.com/jVirus/extensions-kit", from: "1.0.0")
]

Manual

You can always use copy-paste the sources method 😄.

🍱 Categories

List of categories for convenient navigation. The numbers represent total number of extensions for a given category + custom types. Each extension file may contain a number of extensions, grouped by a category.

🙋‍♀️🙋‍♂️Contributing

  • There is just one main rule for contributors - please include your extensions in separete files. It's important since such extension can be more easily referenced and reused.
  • The other soft rule is - please include unit tests with your extensions.

👨‍💻 Author

Astemir Eleev

🔖 Licence

The project is available under MIT licence

extensions-kit's People

Contributors

eleev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

extensions-kit's Issues

The upcoming 1.6.0 update

The next update will bring support for the following extensions:

Foundation

Data Structures

  • Lens - Lens is an implementation of Functional Lenses concept that allows to safely modify immutable structs and provides fundamental tools to work with complex data structures (see UnitTests)

Functions

  • FunctionalComposition - is a functions that implements Functional Composition concept which allows to combine multiple functions and chain them together, in order to transform data. Consider the following construction: (doubleNumbers ->> squareNumbers ->> convertToStringArray)(array) which returns a processed array by linearly composing the functions (rather that nesting the function calls)

Int

String

  • String+Validation - contains a number of extensions for validating String based on the following: isAlphanumeric, hasLetters, hasNumbers, isEmail, isAlphabetic

UIKit

UIApplication

  • UIApplication+SafeAreas - contains extensions that allow to get numerical representations of top and bottom safe areas

UIView

  • UIView+Constraints - adds convenience auto-layout methods that allow to pin, add, get height & width and to get all the constrains for a particular UIView
  • UIView+LayoutAnimation - adds animation extensions that operate on layout constraints

Next 1.4.0 update

The next update will include the following extensions:

Foundation

Custom Types

  • ObjectPool - thread-safe implementation of ObjectPool design pattern
  • Observer - thread-safe implementation of Observer design pattern (don't confuse with NotiifcationCenter - it's an implementation of Publish-Subscribe pattern)
  • MulticastDelegation - non thread-safe implementation of MulticastDelegation design pattern

Extensions

Date

  • Date+FirstLast - adds a number of properties that allow to quickly access: first day of a week, start of a day, end of a day and a number of days in a month
  • Date+PreviousNext - adds properties that allow to get access to the previous and next days

Array

Sequence

  • Sequence+Count - counts the number of occurrences of a logical expression

Grand Central Dispatch

  • Atomic - guarantees that a valid value will be returned when accessing such property by using multiple thread
  • Mutex - used to proptect shared resources. A mutex is owned by the task that takes it. In a given region of code only one thread is active
  • ReadWriteLock - a synchronization primitive that solves one of the readers–writers problems
  • UnfairLock - a lock which causes a thread trying to acquire it to simply wait in a loop ("spin") while repeatedly checking if the lock is available

The update also brings support for Swift 4.2 and adds minor changes that guarantee conformance to the latest SDK.

Next update 1.2.0

The next update will include the following extensions:

Added new category:

  • CoreImage
    • HighlightFilter - the filter is originally designed for highlighting 3D objects but can be used to add this effect to images and sprites
  • Array
    • Array+Union - unions self and the input arrays
    • Array+Contains - checks if self contains the specified elements
    • Array+Difference - computes differences between self and the input arrays
    • Array+Intersection - computes intersection of self and the input values
  • Dictionary
    • Dictionary+ConvenienceWrappers - adds wrappers around common operations such as has(key: )->Bool and each(: (Key, Value)->())
    • Dictionary+Difference - computes differences between self and the input dictionaries
    • Dictionary+Union - unions self and the input dictionaries
    • Dictionary+Intersection - computes intersection of self and the input Dictionaries
    • Dictionary+Map - custom mapping function

Broken links in Readme

The links don’t properly function in Readme file. They need to be fixed til the 1.0.0 version

The upcoming 1.8.0 update

The next update (index 1.8.0 version number index) will bring the following changes, extensions and custom types:

CoreImage

CIImage+Inverted

Inverts the colors of self:

let invertedImage = ciImage.inverted
// invertedImage holds the same image data but with inverted colors

CIImage+QRImage

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

CIImage+Tinted

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

CIImage+Transparent

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

NotificationCenter+PostUtils

Various utility extensions that help to reduce the boilerplate code:

NotificationCenter.post(notification: .userHasUpdated)

OperationQueue

OperationQueue+MainUtils

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

NSObjectProtocol+KVO+KVC

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

FileOutputStream

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. 

UnicodeOutputStream

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

Identifiable

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)

Then

Protocol for object configuration:

var imageView = UIImageView().then {
        $0.layer.cornerRadius = 10
        $0.contentMode = .scaleAspectFill
        $0.clipsToBounds = true
}

Custom Type

Debouncer

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"

ObservableArray

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

URL+QRImage

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

UIWindow+Instantiate

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

UIViewController+ContainerController

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

UIImage+Downsample

Downsamples the input image to the specified point size and scale factor. Can be used to present the thumbnails, supports caching:

UIColor

UIColor+Blend

Blends two colors by mixing the RGBA components:

let blendedColor = red.blend(with: blue, intensity: 0.5)

UIColor+Brightness

Changes the brightness of a color:

let brighterRed = red.increaseBrightness(0.25)

os

OSLog

OSLog+LogLevels

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

SCNAction+MoveAlong

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.

The next 1.7.0 update

The next update will bring support for the following extensions & improvements (the list is in development and will be changing):

Foundation

Functions

  • FunctionalComposition - is a functions that implements Functional Composition concept which allows to combine multiple functions and chain them together, in order to transform data. Consider the following construction: (doubleNumbers ->> squareNumbers ->> convertToStringArray)(array) which returns a processed array by linearly composing the functions (rather that nesting the function calls). Also the extension includes the reversed operator that composes functions in reversed order.

Data Structures

  • Lens - the update brings support for the refactored generic placeholder names (C->Whole, V->Part, U->Subpart)

Collection

  • Collection+SafeSubscript - safely checks whether the collection is able to retreive an element for the given Index, otherwise it will return nil

MutableCollection

  • MutableCollection+Shuffle - the implementation of shuffle algorithm had some performance issues - it was re-implemented from scratch

RandomAccessCollection

UIKit

Implemented custom proxy for CACornerMask struct called UICorner that is embedded into UIView. The struct allows to more conveniently encode and decode rounded corners for CoreAnimation.

UIScreen

UIView

NSLayoutConstraint

SpriteKit

SKScene

  • SKScene+ReferenceNodeFix - a small fix that resolves the default behavior for nodes that were referenced from differnet .sks files. The thing is that they do not launch their animations by default, so this small hack fixes this issue

The next 1.5.0 update

The next update should include the following changes:

  • Add more code coverage
  • Implement the following data structures:
    • Stack
    • Linked List
    • Doubly Linked List
    • Queue
    • Priority Queue
    • Dequeue
    • Heap
  • More extensions related to UIKit
  • More extensions related to CoreAnimation
  • CoreGraphics extensions

Core Graphics

CGSize

  • CGSize+Operators - adds various mathematical operators such as +, -, *, / for convenience

Core Animation

CAAnimation

Foundation

Custom Types

  • Stack - is an implementation of Stack data structure
  • Queue - is an implementation of Queue data structure
  • ProrityQueue - is an implementation of Prority Queue data structure based on Heap data structure
  • Dequeue - is an implementation of Dequeue data structure
  • LinkedList - is an implementation of Linked List data structure
  • DoublyLinkedList - is an implementation of Doubly Linked List data structure
  • Heap - is an implementation of Heap data structure

UIKit

UIViewController

  • UIViewController+Storyboard - instantiates a UIViewController instance from a Storyboard using the UIViewController's name as a reference name of the Storyboard file. Used in cases when Coordinator or Flow design patterns need to be implemented

UICollectionView

UIView

UITableView

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.