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
class Person: CustomStringConvertible { | |
let name: String | |
var residence: String? | |
init(name: String,residence: String) { | |
self.name = name | |
self.residence = residence | |
} | |
var description: String { |
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 map<T,S,U>(_ f: @escaping (T)->S, _ g: @escaping (S)->U) -> (T) -> U { | |
return {x in g(f(x)) } | |
} | |
let countNumberOfDigits = map( { (n: Int) in "\(n)" }, { (str: String) in str.characters.count } ) | |
countNumberOfDigits(12345) |
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 Dictionary where Value: Collection { | |
/// A Boolean value indicating whether all collection-values in dictionary is empty. | |
var isContentsEmpty: Bool { | |
for collection in values where !collection.isEmpty { | |
return false | |
} | |
return 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
extension String { | |
/// Finds and returns the range of the first occurrence of a given string within a given left and right occurencies Strings. | |
func rangeBetween(leftStringOccurence: String, rightStringOccurence: String) -> Range<String.Index>? { | |
guard let lowerBound = self.range(of: leftStringOccurence)?.upperBound, | |
let upperBound = self.range(of: rightStringOccurence)?.lowerBound, | |
lowerBound < upperBound else { | |
return nil | |
} | |
return lowerBound..<upperBound | |
} |
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
enum Style { | |
case normal | |
case uppercased | |
} | |
extension Style { | |
func applyLetterCaseToText(_ text: String) -> String { | |
switch self { | |
case .normal: | |
return text |
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
class A {} | |
class B: A {} | |
class C: A {} | |
extension A: CustomStringConvertible { | |
var description: String { | |
return "type of: \(type(of: 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
// from ExistentialCollection.swift.gyb | |
@inline(never) | |
internal func _abstract( | |
file: StaticString = #file, | |
line: UInt = #line | |
) -> Never { | |
fatalError("Method must be overridden", file: file, line: line) | |
} |
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
class MutableBox<T> { | |
var value: T | |
init(value: T) { | |
self.value = value | |
} | |
} | |
extension MutableBox: CustomDebugStringConvertible { | |
var debugDescription: String { |
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
/// Class file structure | |
// MARK: - Internal Properties | |
// MARK: - Private Properties | |
// MARK: - Init / Deinit | |
// MARK: - Public Methods |
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
#!/bin/sh | |
directories=(Example Source Tests) | |
for directory in "${directories[@]}" | |
do | |
echo "Cleaning whitespace in directory: $directory" | |
find $directory -iregex '.*\.swift' -exec sed -E -i '' -e 's/[[:blank:]]*$//' {} \; | |
done |
OlderNewer