# All files / lib/detectors swift-detector.js

91.66% Statements 11/12
100% Branches 10/10
100% Functions 1/1
91.66% Lines 11/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42

    4x
    4x

    4x
    1x

    3x

    3x
    2x
    2x

    2x
    1x

    3x

     import fs from 'fs-extra';
    import path from 'path';
    import { glob } from 'glob';

    export async function detectSwiftStack(cwd) {
      const podfilePath = path.join(cwd, 'Podfile');
      const xcodeproj = await glob('*.xcodeproj', { cwd, absolute: false });

      if (xcodeproj.length === 0 && !(await fs.pathExists(podfilePath))) {
        return { detected: false };
      }

      let framework = 'swiftui'; // Default to SwiftUI for modern iOS

      // Read Podfile to check for UIKit patterns
      if (await fs.pathExists(podfilePath)) {
        try {
          const podfile = await fs.readFile(podfilePath, 'utf-8');
          // If no SwiftUI mention, assume UIKit
          if (!podfile.toLowerCase().includes('swiftui')) {
            framework = 'uikit';
          }
        } catch (error) {
          console.error('Error reading Podfile:', error);
        }
      }

      return {
        detected: true,
        stack: 'swift-ios',
        confidence: xcodeproj.length > 0 ? 'high' : 'medium',
        language: 'swift',
        framework,
        testRunner: 'xctest',
        linter: 'swiftlint',
        formatter: null,
        buildTool: 'xcodebuild',
        evidence: {
          files: [podfilePath, ...xcodeproj],
        },
      };
    }