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 str = "dupa\r\nblada" | |
for i in str.indices { | |
switch str[i] { | |
case "\n": | |
print("\\n found") // \n not found | |
case "\r": | |
print("\\r found") // \r not found | |
case "\r\n": | |
print("\\r\\n found") // found | |
default: |
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 | |
/* | |
D | |
O | |
O | |
G R | |
S | |
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 bom: String = "\u{feff}" // The character \uFEFF is the BOM character for all UTFs (8, 16 LE and 16 BE) |
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 str = "abc😂" | |
str.count // 4 | |
str.utf16.count // 5 | |
str.utf8.count // 7 | |
import Foundation | |
(str as NSString).length // 5 | |
(str as NSString).lengthOfBytes(using: String.Encoding.utf8.rawValue) // 7 |
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: Equatable { | |
let name: String | |
init(name: String) { | |
self.name = name | |
} | |
static func ==(lhs: A, rhs: A) -> Bool { | |
return lhs.name == rhs.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
import Foundation | |
class Node: Equatable, CustomStringConvertible { | |
let value: Int | |
var children: [Node] | |
init(value: Int, children: [Node]) { | |
self.value = value | |
self.children = children | |
} |
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
// macOS 11.0 (20A5395g) | |
// Xcode 12.2 beta 3 (12B5035g) | |
class MyView: NSView { | |
override init(frame frameRect: NSRect) { | |
super.init(frame: frameRect) | |
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(1)) { | |
let rect = NSRect(x: 10, y: 10, width: 10, height: 10) |
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://github.com/apple/swift-algorithms | |
import Algorithms | |
extension String { | |
func lineChunks() -> [Self.SubSequence] { | |
chunked { | |
!( | |
($0.isNewline && !$1.isNewline) || ($0.isNewline && $1.isNewline) && !($0 == "\r" && $1 == "\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
# .zshrc | |
# Close Xcode on git checkout | |
git() { | |
if [[ $1 == "checkout" ]]; then | |
osascript -e 'quit app "Xcode"' | |
command git "$@"; | |
else | |
command git "$@"; | |
fi; | |
} |