स्निपेट·मुफ़्त
Swift स्निपेट
20 Swift स्निपेट: optional, enum और Result, extension वाले protocol, async/await और URLSession, Codable, SwiftUI व्यू और state, एक @Observable मॉडल और XCTest। कुछ के लिए Swift 5.9 या iOS 17 चाहिए।
मुफ़्त में इंस्टॉल करें।
अगर आपके Android डिवाइस पर PocketCode इंस्टॉल है, तो यह पेज ऐप में खुलेगा।
प्रीव्यू
20 में से 5
Unwrap with if letiflet
Run a block only when the optional has a value
if let ${1:user} = ${2:currentUser} {
$0
}Switch over an enumswitchenum
Switch with one case per enum value
switch ${1:direction} {
case .${2:north}:
$0
case .${3:south}:
break
}Protocol with a default implementationprotoc
Protocol plus an extension that every conforming type gets for free
protocol ${1:Describable} {
var ${2:summary}: String { get }
}
extension ${1:Describable} {
func describe() {
print(${2:summary})
}
}Async throwing functionasyncf
Function called with try await
func ${1:fetchUser}(id: ${2:Int}) async throws -> ${3:User} {
$0
}Task with error handlingtaskb
Start async work from synchronous code and catch its errors
Task {
do {
${1:try await load()}
} catch {
print(error)
}
}1.0.0 में बदलाव
पहला संस्करण।