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
action_sheet_warning: | |
name: "Action sheets must define a source view and rect, or barButtonItem" | |
message: "Action sheets on iPad will crash unless they have a source view and rect, or a source barButtonItem on their popoverPresentationController. If you have done this, you can suppress this warning but not before (swiftlint:disable:this action_sheet_warning)." | |
regex: "UIAlertController\\(.*, preferredStyle: .actionSheet\\)" | |
severity: warning |
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 some text downloaded from an API! |
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 doStuff() { | |
keyInput.constrain(toSuperviewSafeArea: .top, .leading, insetBy: 16) | |
blurView.contentView.addSubview(valueInput) | |
valueInput.constrain(toSuperviewSafeArea: .trailing, .bottom, insetBy: 16) | |
verticalLayoutConstraint = keyInput.constrain(.bottom, to: valueInput, .top, withOffset: -8) | |
verticalLayoutConstraint.priority = .defaultHigh | |
verticalLayoutConstraint.isActive = false | |
sameWidthConstraint = keyInput.constrain(.width, to: valueInput, .width) | |
sameTopConstraint = keyInput.constrain(.top, to: valueInput, .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
import UIKit | |
extension UIView { | |
func constrain(toSuperview edges: NSLayoutAttribute..., insetBy inset: CGFloat = 0) { | |
for edge in edges { | |
constrain(toSuperview: edge, withOffset: offset(for: edge, ofInset: inset)) | |
} | |
} |
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 displayErrorMessage(_ optionalMessage: String?) { | |
if let message = optionalMessage { | |
print(message) | |
} | |
} | |
displayErrorMessage("Something went wrong") // Prints out "Something went wrong" | |
displayErrorMessage(nil) // doesn't do anything |
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
#!/bin/bash | |
if hash lines 2>/dev/null ; then | |
if [ -f imports.txt -o -f lines.txt ]; then | |
echo "Previous import.txt and/or lines.txt exist! Delete them first." | |
exit | |
fi | |
imports > imports.txt && lines > lines.txt | |
open imports.txt lines.txt |
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 completion<Result>(onResult: @escaping (Result) -> Void, onError: @escaping (Error) -> Void) -> ((Result?, Error?) -> Void) { | |
return { (maybeResult, maybeError) in | |
if let result = maybeResult { | |
onResult(result) | |
} else if let error = maybeError { | |
onError(error) | |
} else { | |
onError(SplitError.NoResultFound) | |
} | |
} |
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
{ | |
"fruits" : [ | |
{ | |
"name" : "Apple", | |
"image" : "https://upload.wikimedia.org/wikipedia/commons/thumb/1/15/Red_Apple.jpg/265px-Red_Apple.jpg", | |
"price" : 35 | |
}, | |
{ | |
"name" : "Banana", | |
"image" : "https://upload.wikimedia.org/wikipedia/commons/thumb/4/44/Bananas_white_background_DS.jpg/320px-Bananas_white_background_DS.jpg", |
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 tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | |
if recipes[indexPath.row].isPromoted { | |
let promotedCell = tableView.dequeueReusableCell(withIdentifier: "promoted", for: indexPath) as! PromotedRecipeCell | |
promotedCell.recipe = recipe | |
promotedCell.promotion = recipe.promotion // we've guarded here using the isPromoted method, so the value is unwrapped | |
return promotedCell | |
} else { | |
let normalCell = tableView.dequeueReusableCell(withIdentifier: "normal", for: indexPath) as! RecipeCell | |
normalCell.recipe = recipe | |
return normalCell |
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 tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | |
if let promotion = recipes[indexPath.row].promotion { | |
let promotedCell = tableView.dequeueReusableCell(withIdentifier: "promoted", for: indexPath) as! PromotedRecipeCell | |
promotedCell.recipe = recipe | |
promotedCell.promotion = promotion | |
return promotedCell | |
} else { | |
let normalCell = tableView.dequeueReusableCell(withIdentifier: "normal", for: indexPath) as! RecipeCell | |
normalCell.recipe = recipe | |
return normalCell |
NewerOlder