Browse Source

Extract WordLimit into its own file to fix Xcode scope resolution.

Moving the enum out of the String extension file restores reliable indexing and clears the WordLimit compile errors across ViewModels.

Co-authored-by: Cursor <cursoragent@cursor.com>
AhtashamShahzad1 1 month ago
parent
commit
6199d7d4ec
2 changed files with 22 additions and 21 deletions
  1. 0 21
      gramora/Utilities/String+WordCount.swift
  2. 22 0
      gramora/Utilities/WordLimit.swift

+ 0 - 21
gramora/Utilities/String+WordCount.swift

@@ -1,26 +1,5 @@
 import Foundation
 
-enum WordLimit {
-    static func message(maxWords: Int) -> String {
-        "Maximum \(maxWords) words allowed."
-    }
-
-    static func apply(_ text: String, maxWords: Int) -> (text: String, exceeded: Bool) {
-        guard text.wordCount > maxWords else { return (text, false) }
-        return (text.truncated(toMaxWords: maxWords), true)
-    }
-
-    static func applyImported(
-        _ text: String,
-        maxWords: Int,
-        setError: (String?) -> Void
-    ) -> String {
-        let (limited, exceeded) = apply(text, maxWords: maxWords)
-        setError(exceeded ? message(maxWords: maxWords) : nil)
-        return limited
-    }
-}
-
 extension String {
     var wordCount: Int {
         let trimmed = trimmingCharacters(in: .whitespacesAndNewlines)

+ 22 - 0
gramora/Utilities/WordLimit.swift

@@ -0,0 +1,22 @@
+import Foundation
+
+enum WordLimit {
+    static func message(maxWords: Int) -> String {
+        "Maximum \(maxWords) words allowed."
+    }
+
+    static func apply(_ text: String, maxWords: Int) -> (text: String, exceeded: Bool) {
+        guard text.wordCount > maxWords else { return (text, false) }
+        return (text.truncated(toMaxWords: maxWords), true)
+    }
+
+    static func applyImported(
+        _ text: String,
+        maxWords: Int,
+        setError: (String?) -> Void
+    ) -> String {
+        let (limited, exceeded) = apply(text, maxWords: maxWords)
+        setError(exceeded ? message(maxWords: maxWords) : nil)
+        return limited
+    }
+}