Skip to content

OlegKetrar/Tools

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tools

Carthage compatible

Features

Reusable package

  • Reusable
  • NibInitable
  • StoryboardInitable

ToolsFoundation package

  • NotificationObserver - convenience auto-unsubscribed observer.
  • Section<Into, Item>
  • HasApply protocol
  • RoutingController
  • various String extensions

Tools package

  • KeyboardObserver
  • SliderAdapter - declarative block-based UICollectionView adapter
  • SearchController - declarative block-based UISearchController abstraction
  • Button - UIButton with with preloader, prevents multiple execution
  • Switch - UISwitch with control of value changing
  • Presentation - abstraction around presenting/dismissing of UIViewControllers
  • UIColor extensions
  • AutoLayout extensions

Requirements

  • Swift 5.2+
  • xCode 11.7+
  • iOS 9.0+

Installation

Swift Package Manager

.package(url: "https://github.com/OlegKetrar/Tools", .exact("0.6")),

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate Tools into your Xcode project using Carthage, specify it in your Cartfile:

github "OlegKetrar/Tools" == 0.6

Run carthage update to build the framework and drag the built Tools.framework into your Xcode project.

Button with preloader

Used disabled state to show preloader on button. Disallow all touchs and hides title and attributedTitle while preloader is active. By setting flag shouldAffectImage to false you can show image while if preloader is active. By default true.

let actionButton = Button(frame: .zero)
...

// you can define preloader color.
// other poperties you can change in the usual way.
actionButton.preloaderColor = .white

// you always need to call `finish` closure and call it only on main queue.
actionButton.start(activity: { (finish) in
  doSomethingAsyncronousWithCallback {
    // finish work and stop `preloader` on button
    DispatchQueue.main.async { finish() }
  }
})

Also you can explicitly control preloader with startPreloader() and stopPreloader().

Switch

Adds control to value changing.

let someSwitch = Switch(frame: .zero)
// setup autolayout

// ask you every time somebody toggle switch.
someSwitch.onShouldChangeValue { (proposedValue) in

  // return `true` to change to `proposedValue` or `false` to not.
  return canEnableSmth(proposedValue)
}

RoutingController

Allows you to define your custom app routes and hanlde them with open(url:) method.

Presentation

Abstraction around present/push and dismiss/pop. Presentation represents just a method for showing view controller. Has three built in methods:

// create presentation for presenting controllers over someMyVC
let modalyOverMyVC = Presentation.present(over: someMyVC)

// create presentation for pushing into someMyNC
let pushIntoMyNC = Presentation.push(into: someMyVC)

// create presentation for presenting over current topmost controller
let modallyOverTopVC = Presentation.presentOverTop()

Then you can use it for displaying specific view controller:

somePresentation.show(someViewControllerToShow, animated: true, completion: {
    // do smth
})

And then unwind it:

somePresentation.hide(animated: true, completion: {
    // do smth
})

You need to hide concrete Presentation which you already show. Presentation does not retain navigation controller or presented view controller presenting view controller.

License

Tools is released under the MIT license. See LICENSE for details.