Skip to content

Add AppStorage initializer for Date? (optional Date) #34

@leogdion

Description

@leogdion

Description

RadiantKit's AppStorage extensions are missing an initializer for optional Date (Date?) types. This prevents using @AppStorage(for:) with AppStored types that have Value = Date?.

Current Behavior

When attempting to use:

public enum Onboarding {
  public enum Glass: RadiantKit.AppStored {
    public static let keyType: RadiantKit.KeyType = .reflecting
    public typealias Value = Date?
  }
}

// Usage:
@AppStorage(for: Onboarding.Glass.self) private var onboardedAt

This results in a compilation error:

error: no exact matches in call to initializer

Expected Behavior

An initializer should exist in AppStorage+ExpressibleByNilLiteral.swift to support Date?:

extension AppStorage where Value: ExpressibleByNilLiteral {
  public init<AppStoredType: AppStored>(
    for type: AppStoredType.Type,
    store: UserDefaults? = nil
  )
  where
    AppStoredType.Value == Value,
    Value == Date? {
    self.init(type.key, store: store)
  }
}

Additional Context

The extension file already includes initializers for:

  • Bool?
  • Int?
  • Double?
  • String?
  • URL?
  • Data?
  • Optional RawRepresentable types

But is missing Date?, which is a common type for tracking timestamps in UserDefaults.

Location

File: Sources/RadiantKit/PropertyWrappers/AppStorage/AppStorage+ExpressibleByNilLiteral.swift

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions