Author: Chris Lattner
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
// @discardableResult to be added | |
// @noescape needs to move to type annotation | |
// needs to add _ for item | |
public func with<T>(item: T, @noescape update: (inout T) throws -> Void) rethrows -> T { | |
var this = item; try update(&this); return this | |
} |
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
// taken from https://opensource.apple.com/source/CF/CF-855.17/CFDate.c | |
CFAbsoluteTime CFAbsoluteTimeGetCurrent(void) { | |
CFAbsoluteTime ret; | |
struct timeval tv; | |
gettimeofday(&tv, NULL); // http://linux.die.net/man/2/gettimeofday | |
ret = (CFTimeInterval)tv.tv_sec - kCFAbsoluteTimeIntervalSince1970; | |
ret += (1.0E-6 * (CFTimeInterval)tv.tv_usec); | |
return ret; | |
} |
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
/* Taken from stackOverflow http://stackoverflow.com/questions/24475792/how-to-use-pull-to-refresh-in-swift */ | |
self.refreshControl = UIRefreshControl() | |
self.refreshControl?.attributedTitle = NSAttributedString(string: "Pull to refresh") | |
self.refreshControl?.addTarget(self, action: "refreshTweets:", forControlEvents: UIControlEvents.ValueChanged) | |
self.tableView.addSubview(self.refreshControl!) | |
func refreshTweets (sender: AnyObject) { | |
NetworkController.controller.fetchTimeLine(timelineType, isRefresh: true, newestTweet: self.tweets?[0], userScreenname: userTimelineShown) { (errorDescription, tweets) -> Void in | |
if errorDescription != 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
db = connect("localhost:27017/test"); | |
var cursor = db.unicorns.find({gender : "m"}); | |
var total = 0; | |
while(cursor.hasNext()) { | |
var obj = cursor.next(); | |
total += (obj.hits || 0); | |
} | |
print(total); |