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 stringsCollection = ["Swi", "ft ", "ro", "cks", "!!"] | |
let finalString = stringsCollection.reduce("", +) | |
// Swift rocks!! |
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 collection = [5, 3, 10, 1, 7] | |
let total = collection.reduce(0, +) | |
// 26 |
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 booleans = [true, true, false, true, false] | |
let booleans2 = [true, true, true, true, true] | |
let result = booleans.reduce(true, { $0 && $1 }) | |
let result2 = booleans2.reduce(true, { $0 && $1 }) | |
print(result) // false | |
print(result2) // true |
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 | |
let lastName: String | |
let birthDate: Date | |
init(name: String, lastName: String, birthDate: String) { | |
let df = DateFormatter() | |
df.dateFormat = "dd-MM-yyyy" | |
self.name = name |
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 { | |
static func randomString(size: UInt) -> String { | |
let stringSet = "0123456789aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ" | |
return (0..<size).reduce("", { (partialResult, _) -> String in | |
let randomIndex = arc4random_uniform(UInt32(stringSet.count)) | |
let charIndex = stringSet.index(stringSet.startIndex, offsetBy: String.IndexDistance(randomIndex)) | |
return partialResult.appending(String(stringSet[charIndex])) | |
}) | |
} |
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 { | |
static func randomString(size: UInt) -> String { | |
let stringSet = "0123456789aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ" | |
return (0..<size).reduce("", stringSet.randomCharacter) | |
} | |
private func randomCharacter(partialResult: String, iterationIndex: UInt) -> String { | |
let randomIndex = arc4random_uniform(UInt32(count)) | |
let charIndex = index(startIndex, offsetBy: String.IndexDistance(randomIndex)) | |
return partialResult.appending(String(self[charIndex])) |
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 { | |
static func randomStringOptimized(size: UInt) -> String { | |
let stringSet = "0123456789aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ" | |
return (0..<size).reduce(into: "", stringSet.randomCharacterOptimized) | |
} | |
private func randomCharacterOptimized(partialResult: inout String, iterationIndex: UInt) { | |
let randomIndex = arc4random_uniform(UInt32(count)) | |
let charIndex = index(startIndex, offsetBy: String.IndexDistance(randomIndex)) |
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
Total time: 2.64654844999313 | |
TotalTimeOptimized: 2.50773054361343 | |
Total time difference: 0.1388179063797 | |
Average: 0.0001388179063797 |
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
// Idea obtained from https://medium.com/@dushyant_db/swift-4-recipe-self-sizing-table-view-2635ac3df8ab | |
// it can be useful if you want to center it in the screen (let's say in an iPad for example), or take up all the available | |
// height. Also it could be used to be placed inside a UIStackView | |
class IntrinsicContentSizeTableView: UITableView { | |
var maxHeight: CGFloat = UIScreen.main.bounds.size.height | |
override var intrinsicContentSize: CGSize { | |
let height = min(contentSize.height, maxHeight) | |
return CGSize(width: contentSize.width, height: height) | |
} |
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
xcrun simctl openurl booted https://www.example.com/faq | |
// https://objectivetidbits.com/2017/06/08/working-with-universal-links-on-ios-simulator/ |
OlderNewer