Преглед изворни кода

docs: explain what is being done w/ URLHintArray

Sam Jaffe пре 3 недеља
родитељ
комит
8584e35d88
2 измењених фајлова са 14 додато и 2 уклоњено
  1. 2 2
      Todos/TodosApp.swift
  2. 12 0
      Todos/ViewModel/URLHintArray.swift

+ 2 - 2
Todos/TodosApp.swift

@@ -30,13 +30,13 @@ struct TodosApp: App {
 
   var body: some Scene {
     WindowGroup {
-        ContentView()
+      ContentView()
     }
     .modelContainer(sharedModelContainer)
     
     #if os(macOS)
     Settings {
-        SettingsView()
+      SettingsView()
     }
     #endif
   }

+ 12 - 0
Todos/ViewModel/URLHintArray.swift

@@ -11,6 +11,18 @@ internal import Combine
 
 typealias URLHintArray = [URLHint]
 
+/**
+ * @brief Provides a UserDefaults-compatibiliy layer for Array<URLHint> that
+ * allows seamless reading/writing on program startup and changes.
+ * We bind this type to its JSON-String representation rather than, say, an
+ * Array of dictionaries because @AppStorage only operates on scalar types.
+ *
+ * @author Sam Jaffe
+ * @author KD Knowledge Diet https://paigeshin1991.medium.com/saving-custom-codable-types-in-appstorage-or-scenestorage-in-swiftui-0073032f3f94
+ *
+ * The \@retroactive guards against the Swift developers changing Array<T> to
+ * comply w/ RawRepresentable in the future
+ */
 extension URLHintArray : @retroactive RawRepresentable {
   public init?(rawValue: String) {
     guard let data = rawValue.data(using: .utf8),