GithubHelp home page GithubHelp logo

tak3mat3k / swiftyhelpers Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jpachecou-zz/swiftyhelpers

0.0 2.0 0.0 34 KB

Swifty Helpers - All things are easier with SwiftyHelpers

License: MIT License

Swift 97.03% Ruby 2.97%

swiftyhelpers's Introduction

SwiftyHelpers

Build Status License MIT

SwiftHelpers is focused on making simpler the most tedious and repeating tasks when it comes to developing in Swift

Requirements

  • iOS 8.0+
  • XCode 7.2+

Installation guide

Dynamic libraries or those made with Swift, require iOS 8.0+

CocoaPods

In order to install through CocoaPods, just add this line in your podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!
pod 'SwiftyHelpers', '~> 0.0.1'

Next, excute in terminal

$ pod install

Manual installation

Just clone the project using this command in terminal:

$ git clone https://github.com/jpachecou/SwiftyHelpers.git

Find a folder named Source and drag onto your project

How to use SwiftyHelpers

First of all: if you are using Cocoapods, you just need to import import SwiftyHelpers module.

Date operators

  • Adding/substracting days to a NSDate

     // Date: 1/1/2016 00:00:00
     let testDate = NSDate(timeIntervalSince1970: 1451606400)
     let addDate = testDate + 1
     print("addDate = \(addDate)") // Prints: addDate = 2016-01-02 00:00:00 +0000
     let subtractDate = testDate - 1
     print("subtractDate = \(subtractDate)") // Prints: subtractDate = 2015-12-31 00:00:00 +0000
  • Checking dates <, >, <=, >=, ==

     // Date: 1/1/2016 00:00:00
     let testDate = NSDate(timeIntervalSince1970: 1451606400)
     if NSDate() > testDate {
     	// Checks if now is greater than that testDate
     }
  • Checking if a given date is between another two dates range <=>

     if NSDate() <=> (lessThanDate, greaterThanDate) {
     	// Checks if a date is within a range of two dates
     }

Operators and UI functions

  • UITableView & UICollectionView

    -In order to make this utility work, there has to be a cell inside of a .xibfile with the same name of the class that the cell is subclassing. Given the case in a tableView:

     
     class FooTableViewCell: UITableViewCell {}
     class FooCollectionViewCell: UICollectionViewCell {}
     /*
     	+-- FooTableViewCell.swift
     	+-- FooTableViewCell.xib
     	+-- FooCollectionViewCell.swift
     	+-- FooCollectionViewCell.xib
     */

    As soon as class and .xib are ready, in order to register cells in a UITableView or UICollectionView, just invoke the <= operator among the tableView/collectionView and the cell.

     self.tableView <= FooTableViewCell.self
     self.collectionView <= FooCollectionViewCell.self

    In order to obtain registered cells, just declare an instance of it with its class:

    • tableView example:

       func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
      		let cell: FooTableViewCell = tableView.cellForClass()
      		// configure cell
      		return cell
      }
    • collectionView example:

       func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
           let cell: FooCollectionViewCell = collectionView.cellForClass(indexPath)
           // Configure cell
           return cell
       }
  • UIView

    • Previously to load a nib file, the UIView subclass and .xib should have equal name in order to instantiate it.

       class FooView: UIView {} 
       /*
       	+-- FooView.swift
       	+-- FooView.xib
       */
       
       guard let fooView: FooView? = loadCustomView() else { return } 
    • Removing recursively subViews from UIView, simply using the removeAllSubViews

    • Public method getSubviewIntoView is used recursively in order to get a specific subView, with a concrete class, inside of the UIView subviews.

       let fooSubview: FooView = getSubviewIntoView(self.view)

      This line will locate the first FooView subview inside of all UIView array of subviews

    • Use UIView and CGRect extensions for the getter and setter of a frame attributes

       let view = UIView()
       // Setters and getters
       view.frame.x = 12
       view.x = 12
       view.y = 34
       view.width = 120
       view.height = 87
       //Only get
       view.midY
       view.maxX

License

SwiftyHelpers is licensed under the MIT-License. See LICENSE for more details.

swiftyhelpers's People

Contributors

jpachecou avatar michelgoni avatar

Watchers

James Cloos avatar Takeshi Kajino 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.