This file contains 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 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 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 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 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 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; | |
} |
This file contains 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
public extension Collection { | |
func anySatisfy(_ predicate: (Self.Element) throws -> Bool) rethrows -> Bool { | |
try reduce(false) { | |
try predicate($1) || $0 | |
} | |
} | |
} |
This file contains 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
// Created by Marcin Krzyzanowski | |
import Foundation | |
public protocol JSONEncodable: Encodable { } | |
public extension JSONEncodable { | |
func toJSON(using encoder: @autoclosure () -> JSONEncoder = JSONEncoder()) throws -> String { | |
try String(decoding: encoder().encode(self), as: UTF8.self) | |
} |
This file contains 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
// Marcin Krzyzanowski | |
// blog.krzyzanowskim.com | |
import Foundation | |
extension URLResourceKey { | |
static let bookmarkAllPropertiesKey = URLResourceKey("NSURLBookmarkAllPropertiesKey") | |
static let fileIDKey = URLResourceKey("_NSURLFileIDKey") | |
static let inode = URLResourceKey.fileIDKey | |
} |