Skip to main content

Overview

Inline Code Replacement allows you to transform your Swift code directly within Xcode using AI-powered suggestions. Select any code and let Parsaa suggest better implementations, complete rewrites, or refactoring options.
Direct Integration: All code transformations happen inline, maintaining your workflow and code context.

How It Works

Basic Usage

1

Select Code

Highlight the code you want to replace or improve:
// Example: Old, verbose code
var result: String = ""
for i in 0..<items.count {
    if i > 0 {
        result += ", "
    }
    result += items[i].name
}
2

Request Replacement

Right-click and select “Replace with AI” or use ⌘⇧R:
  • Choose from multiple replacement options
  • Preview changes before applying
  • Get explanations for each suggestion
3

Apply Changes

Select your preferred replacement and apply it directly to your code:
// Parsaa's suggestion: More Swift-like approach
let result = items.map(\.name).joined(separator: ", ")

Replacement Types

Code Optimization

Transform verbose or inefficient code into more Swift-like implementations:
Before:
var numbers: [Int] = []
for i in 0..<array.count {
    if array[i] > 0 {
        numbers.append(array[i] * 2)
    }
}
After:
let numbers = array.compactMap { $0 > 0 ? $0 * 2 : nil }
Before:
var result = ""
for word in words {
    if !result.isEmpty {
        result += " "
    }
    result += word.capitalized
}
After:
let result = words.map(\.capitalized).joined(separator: " ")
Before:
var isValid = false
if email.contains("@") && email.contains(".") {
    isValid = true
}
After:
let isValid = email.contains("@") && email.contains(".")

Refactoring Patterns

Apply common Swift patterns and best practices:
Before:
func processUser() {
    // 50 lines of complex logic
    let name = user.name
    let email = user.email
    // ... more processing
}
After:
func processUser() {
    let userInfo = extractUserInfo()
    validateUserInfo(userInfo)
    // ... rest of processing
}

private func extractUserInfo() -> UserInfo {
    return UserInfo(name: user.name, email: user.email)
}
Before:
class User {
    var name: String
    var email: String
    
    init(name: String, email: String) {
        self.name = name
        self.email = email
    }
}
After:
class User: Codable, Equatable {
    var name: String
    var email: String
    
    init(name: String, email: String) {
        self.name = name
        self.email = email
    }
    
    static func == (lhs: User, rhs: User) -> Bool {
        return lhs.name == rhs.name && lhs.email == rhs.email
    }
}
Before:
func loadData() -> String? {
    if let data = try? Data(contentsOf: url) {
        if let string = String(data: data, encoding: .utf8) {
            return string
        }
    }
    return nil
}
After:
func loadData() throws -> String {
    let data = try Data(contentsOf: url)
    guard let string = String(data: data, encoding: .utf8) else {
        throw DataError.invalidEncoding
    }
    return string
}

Advanced Features

Multiple Replacement Options

When you request a replacement, Parsaa provides multiple options:
1

View Options

Parsaa shows you 3-5 different approaches:
  • Option 1: Most Swift-like (functional approach)
  • Option 2: Performance optimized
  • Option 3: Most readable
  • Option 4: Memory efficient
  • Option 5: Async/await version
2

Compare Approaches

Each option includes:
  • Code preview
  • Performance characteristics
  • Memory usage
  • Readability score
  • Compatibility notes
3

Choose Best Fit

Select the option that best fits your:
  • Performance requirements
  • Code style preferences
  • Team standards
  • Project constraints

Context-Aware Replacements

Parsaa considers your project context when suggesting replacements:
UIKit Context:
// Parsaa knows you're using UIKit
// Suggests: DispatchQueue.main.async for UI updates
DispatchQueue.main.async {
    self.tableView.reloadData()
}
MVVM Context:
// Parsaa suggests ObservableObject patterns
class ViewModel: ObservableObject {
    @Published var items: [Item] = []
}
High-Performance Context:
// Parsaa suggests optimized approaches
let result = array.lazy.map { $0 * 2 }.filter { $0 > 10 }

Replacement Categories

Performance Optimizations

Memory Efficiency

Reduce memory allocations and improve garbage collection.

CPU Optimization

Optimize algorithms and reduce computational complexity.

I/O Improvements

Minimize disk and network operations.

Concurrency

Add async/await patterns and concurrent processing.

Code Quality Improvements

Readability

Make code more readable and self-documenting.

Maintainability

Improve code structure for easier maintenance.

Testability

Make code more testable with dependency injection.

Documentation

Add inline documentation and comments.

Best Practices

When to Use Replacements

  • Good Candidates
  • Avoid Replacing
  • Verbose or repetitive code
  • Performance bottlenecks
  • Legacy code patterns
  • Code that violates Swift conventions

Review Before Applying

Always Review: Always review AI suggestions before applying them to ensure they meet your requirements and don’t introduce bugs.
1

Understand Changes

  • Read through the suggested code
  • Understand the logic flow
  • Check for potential issues
2

Test Functionality

  • Ensure the replacement maintains the same behavior
  • Check edge cases and error conditions
  • Verify performance characteristics
3

Consider Impact

  • Review changes with your team
  • Check for breaking changes
  • Update tests if necessary

Keyboard Shortcuts

ShortcutAction
⌘⇧RReplace selected code
⌘⇧OOptimize selected code
⌘⇧FRefactor selected code
⌘⇧MModernize selected code
⌘⇧PPreview replacement

Troubleshooting

Common Issues

Solutions:
  1. Ensure code is properly selected
  2. Try selecting different code portions
  3. Check if code is too complex
  4. Verify Parsaa is active and connected
Solutions:
  1. Provide more context about your requirements
  2. Select more specific code sections
  3. Use the feedback feature to improve suggestions
  4. Try different replacement categories
Solutions:
  1. Use version control to revert changes
  2. Review the replacement more carefully
  3. Test in a separate branch first
  4. Contact support for complex issues

Tips for Better Results

Select Appropriate Code

Choose code that would benefit from improvement or follows outdated patterns.

Provide Context

Mention your performance requirements, coding standards, or specific goals.

Review Multiple Options

Compare different replacement options to find the best fit.

Test Thoroughly

Always test replacements in a safe environment before applying to production code.
Pro Tip: Use the preview feature to see how replacements will look in your code before applying them. This helps you make informed decisions about which suggestions to use.