uikit-expert-skill 是做什麼的?
使用 AI 代理技能提供準確、高效且現代的 UIKit Swift 程式碼,專注於最佳實踐與效能最佳化。
功能
- 產出遵循 Apple 官方 UIKit 最佳實踐的程式碼。
- 自動套用效能最佳化技術,例如 cell 重用、避免離屏渲染與漸進式載入。
- 支援 SwiftUI 與 UIKit 的無縫整合模式。
- 根據使用者需求,推薦合適的 UIKit 元件與架構。
- 提供詳細的中文註解,協助開發者理解程式碼邏輯。
使用方式
- 在支援 AI 代理的開發環境中安裝此技能(例如 Cursor 或 Codex)。
- 於對話中描述您的 UIKit 需求,例如:
- 「建立一個可重用的自訂 UITableViewCell,支援動態高度與圖片快取。」
- 「實作一個符合現代 iOS 標準的導航控制器動畫過渡效果。」
- AI 代理將產生對應的 Swift 程式碼,包含必要的 import 與最佳化建議。
支援平台
- Claude Code
- Cursor
- Codex
- 其他相容的 AI 代理工具
範例
自訂 UITableViewCell
import UIKit
class CustomTableViewCell: UITableViewCell {
static let reuseIdentifier = "CustomTableViewCell"
private let thumbnailImageView: UIImageView = {
let imageView = UIImageView()
imageView.contentMode = .scaleAspectFill
imageView.clipsToBounds = true
imageView.translatesAutoresizingMaskIntoConstraints = false
return imageView
}()
private let titleLabel: UILabel = {
let label = UILabel()
label.font = UIFont.systemFont(ofSize: 16, weight: .medium)
label.translatesAutoresizingMaskIntoConstraints = false
return label
}()
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
setupView()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) 尚未實作")
}
private func setupView() {
contentView.addSubview(thumbnailImageView)
contentView.addSubview(titleLabel)
NSLayoutConstraint.activate([
thumbnailImageView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 16),
thumbnailImageView.centerYAnchor.constraint(equalTo: contentView.centerYAnchor),
thumbnailImageView.widthAnchor.constraint(equalToConstant: 50),
thumbnailImageView.heightAnchor.constraint(equalToConstant: 50),
titleLabel.leadingAnchor.constraint(equalTo: thumbnailImageView.trailingAnchor, constant: 12),
titleLabel.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -16),
titleLabel.centerYAnchor.constraint(equalTo: contentView.centerYAnchor)
])
}
func configure(with title: String, image: UIImage?) {
titleLabel.text = title
thumbnailImageView.image = image
}
override func prepareForReuse() {
super.prepareForReuse()
thumbnailImageView.image = nil
titleLabel.text = nil
}
}
注意事項
- 本技能專注於 UIKit,不涵蓋 SwiftUI 的獨立功能。
- 建議搭配 Xcode 的 Interface Builder 或程式碼設定以達到最佳效果。
- 對於進階效能問題,請參閱 Apple 官方文件。
授權條款
本技能以 MIT 授權條款釋出。詳情請見 LICENSE 檔案。