用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/ffsshhttiikk/opencode-agents-skills --skill swift命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
基于 SOC 职业分类
正在显示 SKILL.md
| name | swift |
| description | Apple's powerful and intuitive programming language |
| tags | ["swift","ios","macos","apple","programming-language","xcode"] |
I provide guidance for programming in Swift, Apple's modern programming language. I cover language fundamentals, advanced features (generics, protocols, result builders), memory management, concurrency with async/await and actors, and Swift Package Manager for dependency management.
Use me when developing iOS, macOS, watchOS, or tvOS applications in Swift, writing performant and safe code leveraging Swift-specific features, or integrating Swift packages into Apple platform projects.
Swift type system with value types (structs, enums) and reference types (classes). Protocol-oriented programming with protocol extensions and associated types. Generics with type constraints and where clauses. Property wrappers for reusable property logic. Result builders for DSL-like syntax. Structured concurrency with async/await and Task groups. Actor isolation for thread-safe state access. Memory management with ARC and weak/unowned references.
Protocol-oriented design with generics:
import Foundation
protocol Identifiable {
associatedtype ID: Hashable
var id: ID { get }
}
struct User: Identifiable, Hashable {
let id: UUID
let name: String
let email: String
}
struct Product: Identifiable, Hashable {
let id: String
let name: String
let price: Decimal
}
final class Cache<T: Identifiable> where T.ID == UUID {
private var storage: [UUID: T] = [:]
private let lock = NSLock()
func insert(_ item: T) {
lock.lock()
defer { lock.unlock() }
storage[item.id] = item
}
func retrieve(id: UUID) -> T? {
lock.lock()
defer { lock.unlock() }
return storage[id]
}
func allItems() -> [T] {
lock.lock()
defer { lock.unlock() }
return Array(storage.values)
}
}
extension Cache: Sequence where T: Identifiable, T.ID == UUID {
func makeIterator() -> AnyIterator<T> {
let items = allItems()
var index = 0
return AnyIterator {
defer { index += 1 }
return index < items.count ? items[index] : nil
}
}
}
Async/await with actors:
import Foundation
actor ImageProcessor {
private var cache: [URL: Data] = [:]
private let networkManager: NetworkManager
init(networkManager: NetworkManager = .shared) {
self.networkManager = networkManager
}
func processImage(from url: URL) async throws -> UIImage {
if let cached = cache[url] {
return try await decodeImage(from: cached)
}
let data = try await networkManager.download(from: url)
cache[url] = data
let image = try await decodeImage(from: data)
return image
}
private func decodeImage(from data: Data) async throws -> UIImage {
try await withCheckedThrowingContinuation { continuation
.global(qos: .userInitiated).async {
image (data: data) {
continuation.resume(throwing: .decodingFailed)
}
continuation.resume(returning: image)
}
}
}
}
: {
decodingFailed
invalidData
}
{
shared ()
( : ) -> {
(data, response) .shared.data(from: url)
httpResponse response ,
().contains(httpResponse.statusCode) {
.invalidResponse
}
data
}
}
Prefer structs and protocols over classes for value semantics and safer code. Use final classes only when inheritance is truly needed. Leverage protocol extensions for default implementations. Use Result type for error handling in completion handlers. Adopt async/await for asynchronous code. Use actors for protecting mutable state across threads. Utilize generics for type-safe, reusable code. Use @MainActor to ensure UI updates happen on the main thread.
Protocol-oriented programming with protocol extensions for default implementations. Builder pattern using memberwise initializers and default parameters. Factory pattern with static factory methods. Strategy pattern with closures or protocol implementations. Observer pattern with Combine publishers or NotificationCenter. Singleton pattern with static constants. Decorator pattern with protocol composition.