This file contains hidden or 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 regex = try NSRegularExpression(pattern: mypattern, options: []) | |
let str = "some string to match" | |
if let result = regex.firstMatchInString(str, options: [], range: NSMakeRange(0, str.characters.count)) { | |
print((str as NSString).substringWithRange((result?.rangeAtIndex(1))!)) | |
} |
This file contains hidden or 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
protocol BaseSection { | |
var cellIdentifier: String { get } | |
func numberOfRows() -> Int | |
func registerIdentifier(tableView: UITableView) | |
func configureCell(cell: UITableViewCell, indexPath: NSIndexPath) | |
} | |
class Section<T, Cell: UITableViewCell>: BaseSection { | |
var rows: [T] = [] | |
var cellIdentifier = "" |
This file contains hidden or 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
struct TableViewSection<T, Cell: UITableViewCell> { | |
var cellIdentifier: String = "" | |
var items: [T] = [] | |
var configureCell: (cell: Cell, item: T, indexPath: NSIndexPath) -> Void | |
} | |
class TableViewDataSource: NSObject, UITableViewDataSource { | |
var sections: [TableViewSection<?, ?>] = [] // I want arbitrary T/Cell types here, what do? | |
// ... |
This file contains hidden or 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
import UIKit | |
class ViewController: UIViewController { | |
// error: 'UISearchController' is only available on iOS 8.0 or newer | |
var searchController: UISearchController? | |
// error: Stored properties cannot be marked potentially unavailable with 'introduced=' | |
@available(iOS 8.0, *) | |
var conditionallyAvailableSearchController: UISearchController? |
This file contains hidden or 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
// these functions take a swift class's statically referenced method and the instance those methods | |
// should apply to, and returns a function that weakly captures the instance so that you don't have | |
// to worry about memory retain cycles if you want to directly use an instance method as a handler | |
// for some object, like NSNotificationCenter. | |
// | |
// For more information, see this post: | |
// http://www.klundberg.com/blog/capturing-objects-weakly-in-instance-method-references-in-swift/ | |
func weakify <T: AnyObject, U>(owner: T, f: T->U->()) -> U -> () { | |
return { [weak owner] obj in |
NewerOlder