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
func maxProfit(prices: [Int]) -> Int { | |
if prices.count < 2 { | |
return 0 | |
} | |
var profit = 0 | |
var min = prices[0] | |
for price in prices { | |
if price - min > profit { |
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
/* | |
* For a more in depth look at the guard statement check out | |
* http://ericcerney.com/swift-guard-statement/ | |
* where I build off the sample shown here. | |
*/ | |
var x: Int? = 0 | |
// Lets me unwrap x and also check a condition on it | |
func fooGuard() { |
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
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) { | |
tableView.beginUpdates() | |
if editingStyle == .Delete { | |
println(self.savedJobs) | |
println("\(indexPath.row) row will be deleted") | |
let deletedJob = self.savedJobs.removeAtIndex(indexPath.row) | |
deleteJobFromCoreData(deletedJob) | |
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Top) |
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
######################### | |
# .gitignore file for Xcode4 / OS X Source projects | |
# | |
# Version 2.1 | |
# For latest version, see: http://stackoverflow.com/questions/49478/git-ignore-file-for-xcode-projects | |
# | |
# 2013 updates: | |
# - fixed the broken "save personal Schemes" | |
# - added line-by-line explanations for EVERYTHING (some were missing) | |
# |
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
//Challenge 5 | |
func reverseString(string: String) -> String { | |
return string.isEmpty ? "" : string.substringFromIndex(string.endIndex.predecessor()) + | |
reverseString(string.substringToIndex(string.endIndex.predecessor())) | |
} |
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
int desiredRow = whatever; | |
int currentRow = 0; | |
for (int section = 0; section < [self.collectionView numberOfSections]; section++) { | |
for (int row = 0; row < [self.collectionView numberOfItemsInSection:section]; row++) { | |
if (currentRow == desiredRow) { | |
indexPath = [NSIndexPath indexPathForRow:row inSection:section]; | |
} | |
currentRow++; | |
} |