SwiftHelpers is focused on making simpler the most tedious and repeating tasks when it comes to developing in Swift
- iOS 8.0+
- XCode 7.2+
Dynamic libraries or those made with Swift, require iOS 8.0+
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
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
First of all: if you are using Cocoapods, you just need to import import SwiftyHelpers
module.
-
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 }
-
UITableView
&UICollectionView
-In order to make this utility work, there has to be a cell inside of a
.xib
file 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 aUITableView
orUICollectionView
, 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 theremoveAllSubViews
-
Public method
getSubviewIntoView
is used recursively in order to get a specific subView, with a concrete class, inside of theUIView
subviews.let fooSubview: FooView = getSubviewIntoView(self.view)
This line will locate the first FooView subview inside of all
UIView
array of subviews -
Use
UIView
andCGRect
extensions for the getter and setter of a frame attributeslet 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
-
SwiftyHelpers is licensed under the MIT-License. See LICENSE for more details.