Text("Hello")
Text("world")
👇 cursor here
import Combine | |
func aPublisher() -> some Publisher { | |
Just(1) | |
} | |
protocol IntNeverPublisher: Publisher where Output == Int, Failure == Never { } | |
extension Just: IntNeverPublisher where Output == Int {} | |
func aIntNeverPublisher() -> some IntNeverPublisher { |
import Combine | |
final class DeviceOrientation: ObservableObject { | |
@Published private(set) var orientation = UIDevice.current.orientation | |
private var listener: AnyCancellable? | |
init() { | |
orientation = UIDevice.current.orientation | |
print(orientation.isPortrait) | |
listener = NotificationCenter.default.publisher(for: UIDevice.orientationDidChangeNotification) | |
.compactMap { ($0.object as? UIDevice)?.orientation } | |
.compactMap{ |
import UIKit | |
class AutoUpdateColor: UIColor { | |
convenience init(lightColor: UIColor, darkColor: UIColor) { | |
if #available(iOS 13.0, *) { | |
self.init { | |
traitCollection in | |
traitCollection.userInterfaceStyle == .dark | |
? darkColor | |
: lightColor | |
} |
before execute, gen xcode project by
swift package generate-xcodeproj
and configure the build setting as you need
then excute the script with two argument
@propertyWrapper struct MustInjected<Value> { | |
private var _value: Value! = nil | |
#if DEBUG | |
let line: UInt | |
let file: StaticString | |
#endif | |
@available(*, unavailable) | |
init(wrappedValue: @autoclosure @escaping () -> Value) { | |
self._value = nil | |
line = #line |
import XCTest | |
enum XCTGetIndexError: Error { | |
case outofRange | |
} | |
func XCTGetIndex<C, T>( | |
_ array: C, with index: C.Index, | |
_ message: @autoclosure () -> String = "Index out of range", | |
file: StaticString = #file, | |
line: UInt = #line) throws -> T | |
where C: RandomAccessCollection, C.Element == T |
struct HardCodedString: ExpressibleByStringLiteral, CustomStringConvertible { | |
private var backing: String | |
@available(*, deprecated, message: "This method was used by compiler, you should not call directly") | |
init(stringLiteral value: String) { | |
self.backing = value | |
} | |
var description: String {backing} | |
} |
import XCTest | |
final class TwitterMathProbramTests: XCTestCase { | |
func testBFS() throws { | |
var q = (1 ..< 10).map(\.description) | |
var res = [String]() | |
var cur = "" | |
while true { | |
if q.isEmpty { break } | |
cur = q.removeFirst() | |
if cur.count == 10 { |