Latest 1.0.0
Homepage https://github.com/jpachecou/SwiftyHelpers
License MIT
Platforms ios 8.0, requires ARC
Frameworks UIKit
Authors

Build Status
SwiftyHelpers
SwiftyHelpers
SwiftyHelpers
SwiftyHelpers
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 8+

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', '~> 1.0.0'

For swift 2 version, put pod 'SwiftyHelpers', '~> 0.1.5'

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.

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 {}
    class FooTableHeaderView: UITableViewHeaderFooterView {}
    class FooCollectionHeaderView: UICollectionReusableView {}
    /*
        +-- FooTableViewCell.swift
        +-- FooTableViewCell.xib
        +-- FooCollectionViewCell.swift
        +-- FooCollectionViewCell.xib
        +-- FooTableHeaderView.swift
        +-- FooTableHeaderView.xib
        +-- FooCollectionHeaderView.swift
        +-- FooCollectionHeaderView.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.

    // Register cell in a table view
    self.tableView <= FooTableViewCell.self
    // Register header or footer in a table view
    self.tableView <= FooTableHeaderView.self
    
    // Register cell in collection view
    self.collectionView <= FooCollectionViewCell.self
    // Register header or footer in collection view
    collectionView <= (HeaderCollectionReusableView.self, UICollectionElementKindSectionHeader)
    collectionView <= (FooterCollectionReusableView.self, UICollectionElementKindSectionFooter)

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

    • Get cell of a tableView, example:

      func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
          let cell: FooTableViewCell = tableView.cellForClass()
          // configure cell
          return cell
      }
    • Get header or footer of a tableView, example:

      func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
          let cell: FooTableHeaderView = tableView.headerFooterForClass()
          // configure cell
          return cell
      }
    • Get cell of a collectionView, example:

      func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
          let cell: FooCollectionViewCell = collectionView.cellForClass(indexPath)
          // Configure cell
          return cell
      }
    • Get header or footer of a collection view, example:

      func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView {
          if kind == UICollectionElementKindSectionHeader {
              let header: HeaderCollectionReusableView = collectionView.supplementaryViewForClass(indexPath, kind: kind)
              // or
              let header: HeaderCollectionReusableView = headerForClass(indexPath)
              // Configure hedaer
              return header
          }
          let footer: FooterCollectionReusableView = footerForClass(indexPath)
          // Configure footer
          return footer
       }
  • 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

    License

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

Latest podspec

{
    "name": "SwiftyHelpers",
    "version": "1.0.0",
    "summary": "Elegant helpers to improve the swift syntax",
    "homepage": "https://github.com/jpachecou/SwiftyHelpers",
    "license": "MIT",
    "authors": {
        "Jonathan Pacheco": "[email protected]"
    },
    "social_media_url": "https://twitter.com/jpachecou",
    "source": {
        "git": "https://github.com/jpachecou/SwiftyHelpers.git",
        "tag": "1.0.0"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "Source/**/*.swift",
    "requires_arc": true,
    "frameworks": "UIKit"
}

Pin It on Pinterest

Share This