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
| func deduplicated() -> [Element] { | |
| var set = Set<String>() | |
| // Whatever property or the entire thing if Hashable | |
| return filter { set.insert($0.name).inserted } | |
| } |
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
| git for-each-ref --format='%(refname)' | | |
| while read branch | |
| do | |
| size=$(git rev-list --disk-usage --objects HEAD..$branch) | |
| echo "$size $branch" | |
| done | | |
| sort -n |
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
| // https://developer.apple.com/documentation/accelerate/compressing_and_decompressing_data_with_input_and_output_filters | |
| import Compression | |
| let sourceString = """ | |
| Lorem ipsum dolor sit amet consectetur adipiscing elit mi | |
| nibh ornare proin blandit diam ridiculus, faucibus mus | |
| dui eu vehicula nam donec dictumst sed vivamus bibendum | |
| aliquet efficitur. Felis imperdiet sodales dictum morbi | |
| vivamus augue dis duis aliquet velit ullamcorper porttitor, |
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 foos: [(id: Int, bar: Int, baz: Int)] = [ | |
| (100, 100, 100), | |
| (2, 100, 100), | |
| (3, 1000, 100), | |
| (1, 101, 100), | |
| (1, 100, 100), | |
| ] | |
| // The comparison will first compare the .id fields and | |
| // only if they are equal will it perform the comparison on the .bar field |
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
| extension String.StringInterpolation { | |
| mutating func appendInterpolation(json JSONData: Data) { | |
| guard let JSONObject = try? JSONSerialization.jsonObject(with: JSONData, options: []), | |
| let jsonData = try? JSONSerialization.data(withJSONObject: JSONObject, options: .prettyPrinted) else { | |
| appendInterpolation("Invalid JSON data") | |
| return | |
| } | |
| appendInterpolation("\n\(String(decoding: jsonData, as: UTF8.self))") | |
| } | |
| } |
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
| extension View { | |
| func debug() -> Self { | |
| print(Mirror(reflecting: self).subjectType) | |
| return self | |
| } | |
| } |
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 Person { | |
| let name: String | |
| init(_ name: String) { | |
| self.name = name | |
| } | |
| } | |
| let people: [Person] = [.init("De Konig"), .init("Pollock"), .init("Rothko"), .init("Kandinsky")] |
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
| script: | |
| - swift package generate-xcodeproj | |
| - xcodebuild test -scheme {YourProject}-Package -destination \ | |
| platform="macOS" -enableCodeCoverage YES | |
| after_success: | |
| - bash <(curl -s https://codecov.io/bash) |
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
| $ swift package generate-xcodeproj | |
| $ xcodebuild test -scheme {YourProject}-Package -destination \ | |
| platform="macOS" -enableCodeCoverage YES |
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
| extension URL: ExpressibleByStringLiteral { | |
| public init(extendedGraphemeClusterLiteral value: String) { | |
| self = URL(string: value)! | |
| } | |
| public init(stringLiteral value: String) { | |
| self = URL(string: value)! | |
| } | |
| } |
NewerOlder