This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
04bbc49892c7ffcb5ce52788628a409715238c448bb931ee17db634197db04cd8c5dc03d3718c87dcf244708e4a5e994d5e34356e64433d9bc16c2bc62be13b426;GoodGuyMat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Mask UIView with rect/path | |
// inverse = false: part inside rect is kept, everything outside is clipped | |
// inverse = true: part inside rect is cut out, everything else is kept | |
// | |
// Usage: | |
// | |
// // - Cuts rectangle inside view, leaving 20pt borders around | |
// let rect = CGRect(x: 20, y: 20, width: bounds.size.width - 20*2, height: bounds.size.height - 20*2) | |
// targetView.mask(withRect: rect, inverse: true) | |
// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let emailStream = emailTextField.bnd_text | |
let passwordStream = passwordTextField.bnd_text | |
let emailErrorStream = emailStream.map { self.validateEmail($0) } | |
let passwordErrorStream = passwordStream.map { self.validatePassword($0) } | |
let errorStream = combineLatest(emailErrorStream, passwordErrorStream).map { | |
[$0, $1].flatMap{ $0 }.filter{ $0 != nil }.first | |
} | |
let formValidStream = errorStream.map{ $0==nil } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
How to use it: | |
1. Add the file to the project | |
2. Append CustomStringConvertible or CustomDebugStringConvertible protocol to the type you want to have description | |
3. Now you can call object.description on any custom Class or Struct you've made |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This is the implementation of Stopwatch class. | |
Usage: | |
1. Add the Stopwatch.swift file to the project | |
2. Create instance and assing the callback function | |
let stopwatch = Stopwatch() | |
stopwatch.callback = self.tick | |
3. Implement the callback function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
What do you need to do to implement working UICollectionView: | |
1. Add UIViewController to the storyboard. | |
2. Create YourViewController class, subclass of the UIViewController. | |
3. Go to the storyboard -> select new View Controller -> Identity Inspector -> set Class to YourViewController. | |
4. Drag'n'drop UICollectionView to the YourViewController in storyboard. | |
5. It will contain one UICollectionViewCell. Otherwise, drag'n'drop UICollectionViewCell to the UICollectionView. | |
5. Go to the storyboard -> select new Cell -> Attributes Inspector -> set Identifier to "YourCell". | |
6. Go to YourViewController file, create reuseIdentifier constant and set it's vaule to "YourCell". | |
7. Go to the storyboard -> drag delegate and dataSource connections from UICollectionView to YourViewController | |
8. Implement UICollectionViewDataSource protocol via Swift extension |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Source: http://stackoverflow.com/a/24029847/1855792 by Nate Cook | |
Implementation of Fisher-Yates (fast and uniform) shuffle for any collection type using Swift 2 Protocol Extensions. | |
The naming and behavior follow Swift 2.0's sort() and sortInPlace() methods. | |
Code: | |
See FisherYatesShuffle.swift file | |
Usage: | |
[1, 2, 3].shuffle() |