Created
December 19, 2024 09:45
-
-
Save juanarzola/ca49a319ddb3ccfbcb7f425a5e300775 to your computer and use it in GitHub Desktop.
A super simple hack to get a short description of SwiftData's PersistentIdentifier suitable for debugging. Format: `{ModelName}/p{Number}`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftData | |
extension PersistentIdentifier { | |
var shortDebugDescription: String { | |
let description = "\(self)" | |
let entityNameRange = description.firstMatch(of: self.entityName)?.range | |
let lastParenthesisRange = description.firstMatch(of: ")")?.range | |
if let entityNameRange, let lastParenthesisRange, | |
entityNameRange.lowerBound < lastParenthesisRange.upperBound { | |
return String(description[entityNameRange.lowerBound..<lastParenthesisRange.lowerBound]) | |
} | |
return description | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment