@@ -54,6 +54,8 @@ extension AttributeScopes {
54
54
public let presentationIntent : PresentationIntentAttribute
55
55
@available ( macOS 13 , iOS 16 , tvOS 16 , watchOS 9 , * )
56
56
public let markdownSourcePosition : MarkdownSourcePositionAttribute
57
+ @available ( FoundationPreview 6 . 2 , * )
58
+ public let listItemDelimiter : ListItemDelimiterAttribute
57
59
58
60
@available ( macOS 13 , iOS 16 , tvOS 16 , watchOS 9 , * )
59
61
public let localizedStringArgumentAttributes : LocalizedStringArgumentAttributes
@@ -437,6 +439,44 @@ extension AttributeScopes.FoundationAttributes {
437
439
public typealias Value = AttributedString . MarkdownSourcePosition
438
440
}
439
441
442
+ @frozen
443
+ @available ( FoundationPreview 6 . 2 , * )
444
+ public enum ListItemDelimiterAttribute : CodableAttributedStringKey , ObjectiveCConvertibleAttributedStringKey {
445
+ public typealias Value = Character
446
+ public typealias ObjectiveCValue = NSString
447
+
448
+ public static let name = NSAttributedString . Key. listItemDelimiter. rawValue
449
+
450
+ public static func objectiveCValue( for value: Character ) throws -> NSString {
451
+ String ( value) as NSString
452
+ }
453
+
454
+ public static func value( for object: NSString ) throws -> Character {
455
+ let stringValue = object as String
456
+ guard stringValue. count == 1 else {
457
+ throw CocoaError ( . coderInvalidValue)
458
+ }
459
+ return stringValue [ stringValue. startIndex]
460
+ }
461
+
462
+ public static func encode( _ value: Character , to encoder: any Encoder ) throws {
463
+ var container = encoder. singleValueContainer ( )
464
+ try container. encode ( String ( value) )
465
+ }
466
+
467
+ public static func decode( from decoder: any Decoder ) throws -> Character {
468
+ let container = try decoder. singleValueContainer ( )
469
+ let text = try container. decode ( String . self)
470
+ guard text. count == 1 else {
471
+ throw DecodingError . dataCorrupted ( DecodingError . Context (
472
+ codingPath: container. codingPath,
473
+ debugDescription: " List item delimeter encoded value must contain only one character / grapheme cluster "
474
+ ) )
475
+ }
476
+ return text [ text. startIndex]
477
+ }
478
+ }
479
+
440
480
#endif // FOUNDATION_FRAMEWORK
441
481
442
482
@frozen
0 commit comments