/ios-skills:arimunandar--legacy-migrationfrom ios-skills
Step-by-step guide for refactoring legacy/spaghetti iOS code to VIP+W Clean Architecture. Covers analysis, characterization tests, and incremental migration.
Ships in ios-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
A systematic approach to refactoring legacy iOS codebases (MVC, Massive ViewController, spaghetti code) to VIP+W Clean Architecture.
Start with screens that are:
Common legacy patterns to identify:
// 🍝 SPAGHETTI: Everything in ViewController
class ProductViewController: UIViewController {
// UI + Business Logic + Networking + Navigation ALL HERE
func loadProduct() {
// Direct API call in ViewController
URLSession.shared.dataTask(with: url) { data, _, _ in
let product = try? JSONDecoder().decode(Product.self, from: data!)
DispatchQueue.main.async {
// UI update mixed with business logic
self.titleLabel.text = product?.name
self.priceLabel.text = "$\(product?.price ?? 0)"
if product?.isOnSale == true {
self.priceLabel.textColor = .red
self.saveBadge.isHidden = false
}
// Navigation logic here too
if product == nil {
self.navigationController?.popViewController(animated: true)
}
}
}.resume()
}
@IBAction func buyTapped() {
// More API calls, validation, navigation...
}
}
Before refactoring, document:
## ProductViewController Analysis
### Responsibilities (Current)
1. Display product details
2. Fetch product from API
3. Format price with currency
4. Show/hide sale badge
5. Handle buy action
6. Navigate back on error
7. Add to cart
### API Calls
- GET /products/{id}
- POST /cart/items
### Navigation
- Pop on error
- Push to checkout on buy
### State
- product: Product?
- isLoading: Bool
- cartItems: [CartItem]
### Side Effects
- Analytics tracking
- Local cart storage
Capture existing behavior before changing anything:
// Test existing behavior (even if messy)
final class ProductViewControllerLegacyTests: XCTestCase {
func test_loadProduct_displaysProductName() {
// Given
let sut = ProductViewController()
let mockProduct = Product(name: "Test", price: 99.99)
// Inject mock somehow...
// When
sut.loadView()
sut.viewDidLoad()
// Then
XCTAssertEqual(sut.titleLabel.text, "Test")
}
func test_loadProduct_onSale_showsSaleBadge() {
// Capture current behavior
}
}
mkdir -p Features/Product
touch Features/Product/ProductViewController.swift
touch Features/Product/ProductInteractor.swift
touch Features/Product/ProductPresenter.swift
touch Features/Product/ProductWorker.swift
touch Features/Product/ProductRouter.swift
touch Features/Product/ProductModels.swift
touch Features/Product/ProductConfigurator.swift
// ProductModels.swift
enum Product {
enum FetchProduct {
struct Request {
let productId: String
}
struct Response {
let result: Result<ProductEntity, ProductError>
}
struct ViewModel {
let title: String
let formattedPrice: String
let showSaleBadge: Bool
let saleBadgeText: String?
}
}
enum AddToCart {
struct Request {
let quantity: Int
}
struct Response {
let result: Result<Void, CartError>
}
struct ViewModel {
let message: String
let isSuccess: Bool
}
}
}
// Protocols
protocol ProductDisplayLogic: AnyObject {
func displayProduct(viewModel: Product.FetchProduct.ViewModel)
func displayAddToCartResult(viewModel: Product.AddToCart.ViewModel)
func displayLoading(isLoading: Bool)
func displayError(message: String)
}
protocol ProductBusinessLogic {
func fetchProduct(request: Product.FetchProduct.Request)
func addToCart(request: Product.AddToCart.Request)
}
protocol ProductPresentationLogic {
func presentProduct(response: Product.FetchProduct.Response)
func presentAddToCartResult(response: Product.AddToCart.Response)
func presentLoading(isLoading: Bool)
func presentError(_ error: Error)
}
protocol ProductWorkerLogic {
func fetchProduct(id: String) async throws -> ProductEntity
func addToCart(productId: String, quantity: Int) async throws
}
protocol ProductRoutingLogic {
func routeToCheckout()
func routeBack()
}
Move API calls from ViewController to Worker:
// BEFORE (in ViewController)
URLSession.shared.dataTask(with: url) { data, _, _ in
let product = try? JSONDecoder().decode(Product.self, from: data!)
// ...
}
// AFTER (in Worker)
final class ProductWorker: ProductWorkerLogic {
private let apiClient: APIClientProtocol
private let cartStorage: CartStorageProtocol
init(
apiClient: APIClientProtocol = APIClient.shared,
cartStorage: CartStorageProtocol = CartStorage.shared
) {
self.apiClient = apiClient
self.cartStorage = cartStorage
}
func fetchProduct(id: String) async throws -> ProductEntity {
let endpoint = ProductEndpoint.getProduct(id: id)
return try await apiClient.request(endpoint)
}
func addToCart(productId: String, quantity: Int) async throws {
let endpoint = CartEndpoint.addItem(productId: productId, quantity: quantity)
try await apiClient.request(endpoint)
cartStorage.addItem(productId: productId, quantity: quantity)
}
}
Move formatting logic from ViewController to Presenter:
// BEFORE (in ViewController)
self.priceLabel.text = "$\(product?.price ?? 0)"
if product?.isOnSale == true {
self.priceLabel.textColor = .red
}
// AFTER (in Presenter)
final class ProductPresenter: ProductPresentationLogic {
weak var viewController: ProductDisplayLogic?
private let currencyFormatter: NumberFormatter = {
let formatter = NumberFormatter()
formatter.numberStyle = .currency
formatter.locale = Locale.current
return formatter
}()
func presentProduct(response: Product.FetchProduct.Response) {
let viewModel: Product.FetchProduct.ViewModel
switch response.result {
case .success(let product):
viewModel = Product.FetchProduct.ViewModel(
title: product.name,
formattedPrice: formatPrice(product.price, isOnSale: product.isOnSale),
showSaleBadge: product.isOnSale,
saleBadgeText: product.isOnSale ? "SALE \(product.discountPercent)% OFF" : nil
)
case .failure(let error):
presentError(error)
return
}
viewController?.displayProduct(viewModel: viewModel)
}
private func formatPrice(_ price: Decimal, isOnSale: Bool) -> String {
let formatted = currencyFormatter.string(from: price as NSDecimalNumber) ?? ""
return formatted
}
}
Move business logic from ViewController to Interactor:
// BEFORE (in ViewController)
// Business decisions mixed with UI
// AFTER (in Interactor)
final class ProductInteractor: ProductBusinessLogic, ProductDataStore {
var presenter: ProductPresentationLogic?
var worker: ProductWorkerLogic?
var router: ProductRoutingLogic?
// DataStore
var product: ProductEntity?
var productId: String?
func fetchProduct(request: Product.FetchProduct.Request) {
presenter?.presentLoading(isLoading: true)
Task { @MainActor in
defer { presenter?.presentLoading(isLoading: false) }
do {
let product = try await worker?.fetchProduct(id: request.productId)
self.product = product
let response = Product.FetchProduct.Response(result: .success(product!))
presenter?.presentProduct(response: response)
} catch {
let response = Product.FetchProduct.Response(result: .failure(.fetchFailed))
presenter?.presentProduct(response: response)
}
}
}
func addToCart(request: Product.AddToCart.Request) {
guard let product = product else { return }
Task { @MainActor in
do {
try await worker?.addToCart(productId: product.id, quantity: request.quantity)
let response = Product.AddToCart.Response(result: .success(()))
presenter?.presentAddToCartResult(response: response)
} catch {
let response = Product.AddToCart.Response(result: .failure(.addFailed))
presenter?.presentAddToCartResult(response: response)
}
}
}
}
// AFTER - Clean ViewController
final class ProductViewController: UIViewController {
// MARK: - VIP
var interactor: ProductBusinessLogic?
var router: ProductRoutingLogic?
// MARK: - UI
private let titleLabel = UILabel()
private let priceLabel = UILabel()
private let saleBadge = UILabel()
private let buyButton = UIButton()
private let loadingIndicator = UIActivityIndicatorView()
// MARK: - Lifecycle
override func viewDidLoad() {
super.viewDidLoad()
setupUI()
fetchProduct()
}
// MARK: - Setup
private func setupUI() {
// Pure UI setup - no business logic
}
// MARK: - Actions
private func fetchProduct() {
guard let productId = router?.dataStore?.productId else { return }
let request = Product.FetchProduct.Request(productId: productId)
interactor?.fetchProduct(request: request)
}
@objc private func buyTapped() {
let request = Product.AddToCart.Request(quantity: 1)
interactor?.addToCart(request: request)
}
}
// MARK: - DisplayLogic
extension ProductViewController: ProductDisplayLogic {
func displayProduct(viewModel: Product.FetchProduct.ViewModel) {
titleLabel.text = viewModel.title
priceLabel.text = viewModel.formattedPrice
saleBadge.isHidden = !viewModel.showSaleBadge
saleBadge.text = viewModel.saleBadgeText
}
func displayAddToCartResult(viewModel: Product.AddToCart.ViewModel) {
if viewModel.isSuccess {
showToast(viewModel.message)
} else {
showError(viewModel.message)
}
}
func displayLoading(isLoading: Bool) {
if isLoading {
loadingIndicator.startAnimating()
} else {
loadingIndicator.stopAnimating()
}
}
func displayError(message: String) {
showAlert(title: "Error", message: message)
}
}
enum ProductConfigurator {
static func configure(productId: String) -> ProductViewController {
let viewController = ProductViewController()
let interactor = ProductInteractor()
let presenter = ProductPresenter()
let worker = ProductWorker()
let router = ProductRouter()
viewController.interactor = interactor
viewController.router = router
interactor.presenter = presenter
interactor.worker = worker
interactor.router = router
interactor.productId = productId
presenter.viewController = viewController
router.viewController = viewController
router.dataStore = interactor
return viewController
}
}
// BEFORE (legacy)
let vc = ProductViewController()
vc.productId = "123"
navigationController?.pushViewController(vc, animated: true)
// AFTER (VIP+W)
let vc = ProductConfigurator.configure(productId: "123")
navigationController?.pushViewController(vc, animated: true)
// New VIP+W tests
final class ProductInteractorTests: XCTestCase {
func test_fetchProduct_success_presentsProduct() async {
// Given
let mockPresenter = MockProductPresenter()
let mockWorker = MockProductWorker()
mockWorker.fetchProductResult = .success(ProductEntity.mock)
let sut = ProductInteractor()
sut.presenter = mockPresenter
sut.worker = mockWorker
// When
sut.fetchProduct(request: .init(productId: "123"))
await waitForAsync()
// Then
XCTAssertTrue(mockPresenter.presentProductCalled)
}
}
// Delete old methods from ViewController
// - loadProduct()
// - All URLSession calls
// - All formatting logic
// - All business logic
Convert legacy tests to VIP+W tests:
// BEFORE: Testing ViewController directly
func test_legacy_loadProduct_displaysName() {
let sut = ProductViewController()
// ...
}
// AFTER: Testing each component
func test_presenter_formatsPriceCorrectly() {
let sut = ProductPresenter()
// ...
}
func test_interactor_fetchesFromWorker() {
let sut = ProductInteractor()
// ...
}
Analysis
Preparation
Extraction
Integration
Verification
// BEFORE
class ViewController {
func save() {
UserDefaults.standard.set(value, forKey: "key")
}
}
// AFTER
protocol StorageProtocol {
func save(_ value: Any, forKey: String)
}
class Worker {
private let storage: StorageProtocol
init(storage: StorageProtocol = UserDefaultsStorage()) {
self.storage = storage
}
}
// BEFORE
func loadData() {
api.fetchUser { user in
api.fetchOrders(userId: user.id) { orders in
api.fetchProducts(orderIds: orders.map { $0.id }) { products in
self.display(user, orders, products)
}
}
}
}
// AFTER
func loadData() async throws {
let user = try await worker.fetchUser()
let orders = try await worker.fetchOrders(userId: user.id)
let products = try await worker.fetchProducts(orderIds: orders.map { $0.id })
return (user, orders, products)
}
// BEFORE
func handleAction(_ action: String) {
switch action {
case "buy": // 50 lines
case "save": // 50 lines
case "share": // 50 lines
// ...
}
}
// AFTER
protocol ActionHandler {
func handle()
}
class BuyHandler: ActionHandler { ... }
class SaveHandler: ActionHandler { ... }
class ShareHandler: ActionHandler { ... }
Before starting any migration, gather requirements using AskUserQuestion:
Question 1: Migration Goal
Question 2: Current State
Question 3: Test Coverage
Question 4: Risk Tolerance
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
ios-architecture, vip-w, clean-architecture, refactoring, legacy-code
npx claudepluginhub jordancoin/ios-skills-collection --plugin ios-skills206 skills in this plugin
/aso-appstore-screenshotsGenerate high-converting App Store screenshots by analyzing your app's codebase, discovering core benefits, and creating ASO-optimized screenshot images using Nano Banana Pro./cleanseReview code for readability, then simplify it to be easy to follow and understand. Use this skill when the user wants to simplify code, improve readability, clean up for handoff, make code skimmable, reduce complexity, refactor for clarity, strip boilerplate, prepare code for future maintainers, or make a codebase easier to pick up. Trigger liberally — any request touching readability, simplification, cleanup, or "make this easier to understand" should use this skill. Also trigger when the user says things like "review this", "clean this up", "tidy this", "make this simpler", "reduce complexity", "flatten this", "strip the noise", or "I want to understand this code quickly next time I open it".
/critical-reasoningApply critical rationalist epistemology (Popper, Deutsch) to evaluate reasoning, identify errors, and refine understanding. Use when the user explicitly requests help with reasoning - phrases like "help me think this through", "does this make sense", "any flaws in this", "what am I missing", "critique this", "is this reasoning sound", "stress test this idea", "devil's advocate", or any request to evaluate arguments, identify logical problems, or improve thinking. Also use when errors in reasoning are significant enough to materially affect the user's goals, even if not explicitly requested.2 plugins ship this exact skill · first indexed Sep 10, 2026
Other plugins' skills for the same job