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
| // Perform various asynchronous tasks and wait for all results | |
| __block NSObject *result1; | |
| __block NSObject *result2; | |
| __block NSObject *result3; | |
| dispatch_group_t dispatchGroup = dispatch_group_create(); | |
| dispatch_group_enter(dispatchGroup); | |
| [self performBackgroundTask:^(NSObject *result) { |
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 Optional where Wrapped == String { | |
| var isNilOrEmpty: Bool { | |
| return (self ?? "").isEmpty | |
| } | |
| } |
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
| // Xcode will notify in the appropiate line when the custom assertion function fails | |
| func assertSomething(with param: InterestingObject, file: StaticString = #file, line: UInt = #line) { | |
| XCTFail("Bad bad", 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
| func description(for percentage: Int?) -> String { | |
| switch percentage { | |
| case .some(0): | |
| return "Minimum value" | |
| case .some(let value): | |
| return "Value: \(value)" | |
| case .none: | |
| return "Value not specified" | |
| } | |
| } |
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
| parse_git_branch() { | |
| git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/' | |
| } | |
| # Appearance | |
| # PS1="\h:\W \u\$" # default | |
| export PS1="\u@\h \[\033[32m\]\W\[\033[33m\]\$(parse_git_branch)\[\033[00m\] $ " | |
| export CLICOLOR=1 | |
| export LSCOLORS=ExFxBxDxCxegedabagacad |
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
| import Foundation | |
| import UIKit | |
| func swiftVersion() -> String { | |
| #if swift(>=4.2.1) | |
| return "4.2.1" | |
| #elseif swift(>=4.2) | |
| return "4.2" | |
| #elseif swift(>=4.1) | |
| return "4.1" |
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 array: [Any] = ["String1", 2, "String2", 3, 4] | |
| for case let str as String in array { | |
| print(str) | |
| } |
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
| # Reset last commit (if changes have not been pushed yet) | |
| git reset --soft HEAD~1 |
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 Data { | |
| let name: String? | |
| let location: String? | |
| var components: String { | |
| return [name, location] | |
| .compactMap { $0 } | |
| .filter { !$0.isEmpty } | |
| .joined(separator: " - ") | |
| } |
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
| switch john.residence?.numberOfRooms { | |
| case .Some(let x) where x % 2 == 0: | |
| println("Even number of rooms") | |
| default: | |
| println("Odd number of rooms") | |
| } |