Code Monkey home page Code Monkey logo

swift-wisdom's Introduction

Build Status SonarQube

This library is meant to be a general grab bag of Swift methods made by the engineers at IntrepidPursuits. As this library goes, useful components will be isolated into separate podspecs where appropriate.

The reason for the grab bag approach is to make it easier to facilitate the adding of materials and encourage componentization and sharing of common functionality.

iOS Versions

  • iOS <= 9 -> <0.11.0

Swift Versions

  • Swift 4.2 -> 0.11.0 +
  • Swift 4.1.50 (Xcode 10 Compatible) -> 0.10.3
  • Swift 4.0 -> 0.9.0 through 0.10.x
  • Swift 3.2 (Xcode 9 Compatible) -> 0.8.3 through 0.8.4
  • Swift 3 -> 0.6.1 through 0.8.1
  • Swift 2 -> anything through 0.5.2

Core

pod 'Intrepid'

Subspecs

pod 'Intrepid/Rx' # Intrepid's RxSwift Extensions

Testing Additions

source 'https://github.com/IntrepidPursuits/swift-wisdom.git'
target 'YourTestTarget',
    use_frameworks!
    pod 'IntrepidSwiftWisdomTesting'
end

Components

Qu

A basic wrapper for dispatch operations in Swift. Syntax example:

    Qu.Background {
        // Sleep for long operation
        sleep(4)
        print("1")
    } .Also {
        sleep(4)
        print("2")
    } .Also {
        sleep(1)
        print("3")
    } .Also {
        sleep(1)
        print("4")
    } .Also {
        sleep(1)
        print("5")
    } .ThenAfter(.previous(3)) {
        print("6: After 5, 4, & 3")
    } .Then {
        sleep(1)
        print("7: After 6")
    } .FinallyOn(.main) {
        sleep(1)
        print("Finished: After All")
    }

After

A simple way to perform or repeat future operations:

After(2.5) {
  print("Two and a half seconds later")
}

RepeatAtInterval(1.0, numberOfTimes: 5) {
  print("Once a second, 5 times")
}

Nib Initable

Load views from nibs:

let myCustomView = MyCustomView.fromNib()

Color Descriptor

Setup Easy Color Schemes. Note, if you're using Zeplin that it auto generates color schemes if you'd like

enum ColorPalette : ColorDescriptor {
    case White = "254,216,130,255"
    case DarkGreen = "51,58,24,255"
    case DarkGray = "64,48,56,255"
    case BrightWhite = "#ffffff"

    var color: UIColor {
        return rawValue.color
    }
}

And use:

someView.backgroundColor = ColorPalette.White.color

Cell Configuring

A simple way to cover most table view registering / dequeing

Register
tableView.ip_registerCell(YourCell.self)
tableView.ip_registerHeader(YourHeader.self)
Dequeue
let cell: YourCell = tableView.ip_dequeueCell(indexPath)
//
let header: YourHeader = tableView.ip_dequeueHeader(section)

User Defaults

A way to read and write from defaults simply and type-safe

Define
enum Setting : String, EnumSettingsKeyAccessible {
    case DisplayName
    case LastOpenDate
}
Read
let displayName: String? = Setting.DisplayName.readFromDefaults
Write
Setting.DisplayName.writeToDefaults(displayName)
Implement
struct ApplicationSettings {
    var displayName: String {
        get {
            return Setting.DisplayName.readFromDefaults ?? ""
        }
        set {
            Setting.DisplayName.writeToDefaults(newValue)
        }
    }
}

Result

As opposed to using objective-c style async completion blocks like (possibleObject: AnyObject?, error: NSError?), Result types are preferable:

func fetchName(completion: Result<String> -> Void)

And use:

fetchName { result in
    switch result {
    case let .Success(name):
        print("Successfully got name: \(name)")
    case let .Failure(error):
        print("Failed to get name: \(error)")
    }

}

Time Of Day

Used to convert times of day back and forth from NSDate

To Time

let date = ...
let timeOfDay = TimeOfDay(date)
// or

let timeOfDay = TimeOfDay("1:30")

To Date:

let timeOfDay = ...

// Time Today
let todayAtThatTime = timeOfDay.timeToday()

// Time on given date
let someDate = ...
let timeOnThatDate = timeOfDay.timeOnDate(someDate)

Contributions

All contributions and updates are welcome! Here's some basic guidelines when submitting an addition:

  • Submit via a Pull Request documenting the addition
  • Follow appropriate folder conventions
  • Prefix all extension methods and variables with ip_ to avoid namespacing. Swift namespacing doesn't apply the same way to extensions and prefixes help avoid issues.
  • Document functionality if it is ambiguous
  • Bump podspec and tag on branch before merging
  • On approval, push the podspec to trunk using pod trunk push Intrepid.podspec.

swift-wisdom's People

Contributors

loganwright avatar paulrolfe avatar brightredchilli avatar tzm41 avatar alexpersian avatar jpmendel avatar bobgilmore avatar benuuu avatar petey3 avatar wingchi avatar cprime avatar elnoss avatar nivektric avatar aspitz-intrepid avatar leeelton avatar dennis-cherchenko avatar eltonium 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.