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
/// Throws error if ALL localizable files does not have matching keys | |
/// | |
/// - Parameter files: list of localizable files to validate | |
func validateMatchKeys(_ files: [LocalizationStringsFile]) { | |
print("------------ Validating keys match in all localizable files ------------") | |
guard let base = files.first, files.count > 1 else { return } | |
let files = Array(files.dropFirst()) | |
files.forEach { | |
guard let extraKey = Set(base.keys).symmetricDifference($0.keys).first else { return } | |
let incorrectFile = $0.keys.contains(extraKey) ? $0 : base |
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
if (resourceIsAvailable) { | |
resourceIsAvailable = false | |
useResource() | |
resourceIsAvailable = true | |
} else { | |
// resource is not available, wait or do something else | |
} |
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
extension UIImage { | |
func load(image imageName: String) -> UIImage { | |
// declare image location | |
let imagePath: String = "\(NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0])/\(imageName).png" | |
let imageUrl: URL = URL(fileURLWithPath: imagePath) | |
// check if the image is stored already | |
if FileManager.default.fileExists(atPath: imagePath), | |
let imageData: Data = try? Data(contentsOf: imageUrl), | |
let image: UIImage = UIImage(data: imageData, scale: UIScreen.main.scale) { |
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 gifts = [ "partridge in a pear tree", "Two turtle doves", "Three French hens", | |
"Four calling birds", "Five golden rings", "Six geese a-laying", | |
"Seven swans a-swimming", "Eight maids a-milking", "Nine ladies dancing", | |
"Ten lords a-leaping", "Eleven pipers piping", "Twelve drummers drumming" ] | |
let nth = [ "first", "second", "third", "fourth", "fifth", "sixth", | |
"seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth" ] | |
func gifts(for day: Int) -> String { | |
var result = "On the \(nth[day-1]) day of Christmas, my true love sent to me:\n" |
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 | |
class MyView: UIView { | |
fileprivate var myPreviewInteraction: Any? = nil | |
init() { | |
super.init(frame: CGRect.zero) | |
if #available(iOS 10.0, *) { | |
myPreviewInteraction = UIPreviewInteraction(view: self) |
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
internal func shortestPath(source: Vertex, destination: Vertex) -> Path? { | |
var frontier: [Path] = [] { | |
didSet { | |
frontier.sortInPlace() | |
} | |
} | |
var finalPaths: [Path] = [] { | |
didSet { | |
finalPaths.sortInPlace() |
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
struct Path: Comparable { | |
let cumulativeWeight: Int | |
let lastNode: Node | |
let previousPath: Path? | |
init(toNode: Node, viaConnection: Connection?=nil, viaPath: Path?=nil) { | |
if let | |
previousPath = viaPath, | |
lastConnection = viaConnection { | |
self.cumulativeWeight = lastConnection.weight + previousPath.cumulativeWeight |
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 ==(x: Path, y: Path) -> Bool { | |
return x.cumulativeWeight == y.cumulativeWeight | |
} | |
func <(x: Path, y: Path) -> Bool { | |
return x.cumulativeWeight < y.cumulativeWeight | |
} |
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
init(toNode: Node, viaConnection: Connection?=nil, viaPath: Path?=nil) { | |
if let | |
previousPath = viaPath, | |
lastConnection = viaConnection { | |
self.cumulativeWeight = lastConnection.weight + previousPath.cumulativeWeight | |
} else { | |
self.cumulativeWeight = 0 | |
} | |
self.lastNode = toNode |
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
struct Path { | |
let cumulativeWeight: Int | |
let lastNode: Node | |
let previousPath: Path? | |
} |