Skip to content

Latest commit

 

History

History
42 lines (29 loc) · 1.35 KB

File metadata and controls

42 lines (29 loc) · 1.35 KB

CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

Project Overview

DetectImageType is an iOS utility that detects image file formats by analyzing binary magic bytes. Supports: PNG, JPEG, JPEG2000, GIF, BMP, TIFF, ICO, ICNS, WebP, HEIC/HEIF, AVIF, and SVG.

Build Commands

# Build
xcodebuild -project DetectImageType.xcodeproj -scheme DetectImageType -sdk iphonesimulator build

# Test
xcodebuild -project DetectImageType.xcodeproj -scheme DetectImageType -sdk iphonesimulator test

Architecture

Core logic is in Data+Extension.swift:

  • ImageType enum with fileExtension and mimeType properties
  • detectImageType() instance method using withUnsafeBytes for efficient byte access
  • detectFtypFormat() helper for HEIC/AVIF detection (ISO base media file format)
  • detectSVG() helper for XML-based SVG detection
  • Static convenience methods for Data, URL, file path, and bundle resources

Magic byte detection order

  1. PNG (8 bytes) → JPEG (3 bytes) → JPEG2000 (4-8 bytes)
  2. GIF (6 bytes) → BMP (2 bytes) → TIFF (4 bytes)
  3. ICO (4 bytes) → ICNS (4 bytes) → WebP (12 bytes)
  4. HEIC/AVIF via ftyp box → SVG via text patterns

Usage

let type = data.detectImageType()
print(type.mimeType)      // "image/png"
print(type.fileExtension) // "png"