# EFQRCode Dependencies: QRCodeSwift, SwiftDraw, and Apple Frameworks Explained

> Explore EFQRCode's core dependencies: QRCodeSwift for QR generation and SwiftDraw for vector graphics. Understand how Apple frameworks like CoreGraphics and UIKit enhance its image rendering and recognition capabilities.

- Repository: [EFPrefix/efqrcode](https://github.com/efprefix/efqrcode)
- Tags: deep-dive
- Published: 2026-03-01

---

**EFQRCode relies on two external Swift packages—QRCodeSwift for QR matrix generation and SwiftDraw for vector graphics—plus Apple system frameworks including CoreGraphics, ImageIO, UIKit/AppKit, CoreImage, and AVFoundation for image rendering, QR recognition, and video export.**

EFQRCode is a cross-platform Swift library for generating and recognizing QR codes across iOS, macOS, tvOS, and watchOS. Understanding the EFQRCode dependencies is essential for developers integrating the library, as it combines specialized third-party packages with native Apple frameworks to handle everything from low-level QR matrix calculation to high-level image and video export.

## Core External Dependencies

The foundation of EFQRCode's functionality rests on two primary external Swift packages declared in [`Package.swift`](https://github.com/efprefix/efqrcode/blob/main/Package.swift).

### QRCodeSwift: The QR Engine

**QRCodeSwift** (https://github.com/EFPrefix/swift_qrcodejs) serves as the core encoding and decoding engine. This dependency handles all low-level QR matrix generation, converting raw data into the binary grid pattern that forms the QR code structure.

In [`Package.swift`](https://github.com/efprefix/efqrcode/blob/main/Package.swift) (lines 42-50), QRCodeSwift is declared as a dependency:

```swift
dependencies: [
    .package(url: "https://github.com/EFPrefix/swift_qrcodejs.git", from: "2.0.0")
]

```

The library interfaces with this package in `Source/EFQRCode+Generator.swift` to generate the base matrix before applying styles and transformations.

### SwiftDraw: Vector Graphics and SVG Support

**SwiftDraw** (https://github.com/swhitty/SwiftDraw) provides vector graphics rendering capabilities, enabling EFQRCode to support SVG output and complex visual styles including bubbles, 2.5-D effects, and custom icon compositing.

Declared in [`Package.swift`](https://github.com/efprefix/efqrcode/blob/main/Package.swift) (lines 44-52), SwiftDraw allows the library to render vector-based QR codes that scale without quality loss:

```swift
dependencies: [
    .package(url: "https://github.com/swhitty/SwiftDraw.git", from: "0.0.8")
]

```

The `Source/Styles/` directory leverages SwiftDraw for advanced rendering modes, particularly when generating QR codes with custom shapes or embedded logos.

## Apple System Frameworks

Beyond external packages, EFQRCode integrates deeply with Apple's native frameworks to handle platform-specific image operations, UI integration, and media export.

### CoreGraphics and ImageIO

**CoreGraphics** (imported in `Source/EFQRCode+Generator.swift` at line 28) provides the low-level bitmap and context drawing operations necessary for rendering QR matrices into `CGImage` objects. **ImageIO** (line 29) handles encoding these images into various formats including PNG, JPEG, GIF, and PDF.

These frameworks enable the `toData()` and `toImage()` methods to produce platform-ready image data.

### UIKit and AppKit

For cross-platform compatibility, EFQRCode conditionally imports **UIKit** (iOS/tvOS/watchOS) and **AppKit** (macOS) in `Source/EFQRCode+Generator.swift` (lines 35-40). These frameworks provide `UIImage` and `NSImage` wrappers around the generated `CGImage` data, allowing seamless integration with native UI components.

The code uses `#if canImport(UIKit)` and `#if canImport(AppKit)` preprocessor directives to maintain a single codebase across all Apple platforms.

### CoreImage for Recognition

The QR recognition functionality relies on **CoreImage** (imported in `Source/EFQRCode+Recognizer.swift` at line 28). This framework provides the `CIDetector` class for identifying QR codes within images, enabling the library to decode existing QR codes rather than just generating new ones.

### AVFoundation for Video Export

For animated QR codes, EFQRCode imports **AVFoundation** and **CoreVideo** in `Source/EFQRCode+Generator.swift` (lines 41-44). These frameworks handle video composition and export, allowing the library to generate MOV or MP4 files containing animated QR code sequences.

### CoreServices for File Types

**CoreServices** and **MobileCoreServices** (lines 30-34 in `Source/EFQRCode+Generator.swift`) provide Uniform Type Identifier (UTI) handling for file export operations, ensuring proper format identification when saving PNG, JPEG, PDF, or SVG files.

## Implementation Architecture

The dependency structure is orchestrated through [`Package.swift`](https://github.com/efprefix/efqrcode/blob/main/Package.swift), which declares the external packages, while the source files in `Source/` handle framework integration.

Key integration points include:

- `Source/EFQRCode+Generator.swift`: Wires QRCodeSwift for matrix generation, SwiftDraw for vector rendering, and Apple frameworks for image/video export
- `Source/EFQRCode+Recognizer.swift`: Uses CoreImage for detection
- `Source/Styles/*.swift`: Leverages SwiftDraw for advanced visual effects
- `Source/Extension/*.swift`: Platform-specific extensions for UIImage/NSImage

## Practical Code Examples

### Basic QR Generation with Core Dependencies

```swift
import EFQRCode

// Generate a simple QR code using QRCodeSwift for encoding
// and CoreGraphics/ImageIO for rendering
do {
    let generator = try EFQRCode.Generator("https://github.com/efprefix/efqrcode")
    let pngData = try generator.toData(width: 300)
    try pngData.write(to: URL(fileURLWithPath: "/tmp/qrcode.png"))
} catch {
    print("Generation failed: \(error)")
}

```

### Vector Graphics with SwiftDraw

```swift
import EFQRCode

// Utilize SwiftDraw for SVG output and complex styling
do {
    let generator = try EFQRCode.Generator(
        "Hello EFQRCode",
        size: 300,
        style: .image(icon: UIImage(named: "logo")!)
    )
    let image = try generator.toImage()
    // Returns UIImage/NSImage via UIKit/AppKit integration
} catch {
    print("Styling failed: \(error)")
}

```

### Video Export with AVFoundation

```swift
import EFQRCode

// Leverage AVFoundation and CoreVideo for animated QR codes
do {
    let generator = try EFQRCode.Generator(
        "Animated QR",
        size: 300,
        style: .basic,
        animated: true,
        frameCount: 30
    )
    let videoURL = try generator.toVideo(
        url: URL(fileURLWithPath: "/tmp/qr.mov"),
        fps: 30
    )
    print("Video saved at \(videoURL)")
} catch {
    print("Video export failed: \(error)")
}

```

## Summary

- **EFQRCode dependencies** center on two external Swift packages: **QRCodeSwift** for low-level QR matrix generation and **SwiftDraw** for vector graphics and SVG support.
- The library integrates extensively with **Apple system frameworks**, including **CoreGraphics** and **ImageIO** for bitmap rendering, **UIKit/AppKit** for platform-specific image objects, **CoreImage** for QR recognition, and **AVFoundation** for video export.
- Dependency declarations reside in [`Package.swift`](https://github.com/efprefix/efqrcode/blob/main/Package.swift), while implementation details are found in `Source/EFQRCode+Generator.swift` and `Source/EFQRCode+Recognizer.swift`.
- The architecture supports cross-platform deployment across iOS, macOS, tvOS, and watchOS through conditional compilation and framework availability checks.

## Frequently Asked Questions

### What are the main external dependencies required by EFQRCode?

EFQRCode relies on two primary external Swift packages: **QRCodeSwift** (https://github.com/EFPrefix/swift_qrcodejs) for generating QR code matrices, and **SwiftDraw** (https://github.com/swhitty/SwiftDraw) for vector graphics rendering and SVG output. These are declared in [`Package.swift`](https://github.com/efprefix/efqrcode/blob/main/Package.swift) and fetched automatically by the Swift Package Manager when you add EFQRCode to your project.

### Does EFQRCode work without UIKit or AppKit?

While the core QR generation logic can function using only **CoreGraphics** and **ImageIO**, full functionality—including conversion to `UIImage` or `NSImage` objects—requires **UIKit** (on iOS/tvOS/watchOS) or **AppKit** (on macOS). The library uses conditional compilation (`#if canImport`) to maintain cross-platform compatibility, but you cannot display or export platform-native image objects without the respective UI framework.

### How does EFQRCode handle video export for animated QR codes?

EFQRCode leverages **AVFoundation** and **CoreVideo** (imported in `Source/EFQRCode+Generator.swift` at lines 41-44) to compose and export animated QR codes as MOV or MP4 files. When you call `toVideo(url:fps:)`, the library uses these frameworks to create a video asset writer, append individual QR code frames generated by **QRCodeSwift**, and encode the final video file to the specified URL.

### Can EFQRCode recognize existing QR codes without additional dependencies?

Yes, QR recognition is handled entirely through **CoreImage** (imported in `Source/EFQRCode+Recognizer.swift` at line 28), which is part of Apple's standard SDK. The `CIDetector` class within CoreImage provides QR code detection capabilities, meaning you do not need to import any additional third-party libraries to scan or decode existing QR codes—only the standard EFQRCode package and Apple's built-in frameworks.