Coder Social home page Coder Social logo

utils's Introduction

Utils

Swift5 Platform iOS License: MIT SPM Compatible Cocoapods Compatible

Utils for iOS development.

Features

Initable

Initialize views/controllers from code/xib/storyboard with one simple interface .initiate()

Controllers example:

// Controller without nib.
class FooController: UIViewController, CodeInitable { }
let foo = FooController.initiate()

// Controller with xib named "FooContoller"
class BarController: UIVewController: XibInitable {
    static var xibName: String { "FooContoller" }
}
let bar = BarController.initiate()

// Controller with storyboard named "BazStoryboard" with id "BazControllerId"
class BazController: UIVewController: StoryboardInitable {
    static var storyboardId: String { "BazControllerId" }
    static var storyboardName: String { "BazStoryboard" }
}
let baz = BazController.initiate()

Initable Example

BundleFileReader

Reading custom object/JSON/Data from Bundle.

Bundle contains foo.json file.

{
    "bar": 100
}

Reading:

struct Foo {
    let bar: Int
}

let foo: Foo = BundleFileReader.readObject("foo")

More about BundleFileReader in action here.

LocalNotificationService

Lightweight tool for managing local notifications. Tools:

  1. Use requestAuthorization to request User's approve for sending notifications
  2. Use getAuthorizationStatus to check current authorization status
  3. Use willPresent to ask the delegate what to do after receiving notification
  4. Use didRecieve to inform delegate about receiving notification

Example:

LocalNotificationService.shared.getAuthorizationStatus { status in
    if status == .authorized { 
        // Do some...
    } else {
        // Do another...
    }
}

LocalNotificationService examle

Extensions

Useful extensions for all code situations

let number = Float.two // 2.0
let closure = Closure.Int // (Int) -> Void
let color = UIColor(hex: "#FFFFFF") // White Color
// and others

Extensions example

MulticastDelegate

MulticastDelegate hepls to manage more than one delegate.

protocol FooDelegate: AnyObject { 
    func bar()
 }

let multicastDelegate = MulticastDelegate<FooDelegate>()

multicastDelegate.add(delegate: object)
multicastDelegate.remove(delegate: object)

multicastDelegate.invokeForEachDelegate { delegate in
    delegate.bar()
}

UIKit.View(Controller) Preview

Live preview for UIKit views/controllers.

class FooView: UIView { ... }

struct FooView_Previews: PreviewProvider {
    static var previews: some View {
        ViewPreview {
            FooView()
        }
    }
}

Button

Base button class with a lots of customization.

Usage from code:

class FooButton: Button { }

Usage from nib:

  1. Set your button class to Button in IB
  2. Set Type = Custom in IB
  3. Set Style = Default in IB

Layout

Simple view layout

let superview = UIView()
let subview = UIView()

superview.layoutSubview(subview, with: LayoutInsets.zero, safe: true)

StackView

StackView with item content builder.

let items = (0..<10).map { Int($0) }
let stackView = ItemsStackView<Int, UILabel>(
    axis: .horizontal,
    distribution: .fill,
    alignment: .fill,
    spacing: 10,
    edgeInsets: .zero,
    items: items
) { item in
    let label = UILabel()
    label.text = "\(item)"
    
    return label
}

Requirements

  • Swift 5.0 +
  • iOS 13.0 +

CocoaPods

  1. Make pod init
  2. Add the following to Podfile
pod 'Utils', :git => 'https://github.com/MobileUpLLC/Utils', :tag => '0.1.0', :branch => 'develop'
  1. Make pod install

Manual

Download and drag files from Source folder into your Xcode project.

Swift Package Manager Install

Swift Package Manager

dependencies: [
    .package(url: "https://github.com/MobileUpLLC/Utils", .upToNextMajor(from: "0.1.0"))
]

License

Utils is distributed under the MIT License.

utils's People

Contributors

vitaliivishnyakov avatar kotliamba avatar timonity avatar denissushkovmobileup avatar petrovichppp avatar frameorigin avatar d-sushkov avatar vgrokhotov avatar

Stargazers

Daniil Smirnov avatar est7 avatar Ilya Biltuev avatar Kirill Kapis avatar

Watchers

James Cloos avatar Maxim Aliev avatar  avatar Artur Artikov avatar

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.