Михаил Капелько 1 year ago
parent
commit
765889a9d6
2 changed files with 17 additions and 15 deletions
  1. +16
    -14
      src/MeetupId.swift
  2. +1
    -1
      src/VM.swift

+ 16
- 14
src/MeetupId.swift View File

@@ -7,21 +7,23 @@ enum MeetupId {
case meetupIdTextUI case meetupIdTextUI
} }


static func shouldFormat(_ s: String) -> String? { static func onlyFormat(_ s: String) -> String? {
let digits = s.components(separatedBy: NSCharacterSet.decimalDigits.inverted).reduce("") { $0 + $1 } let digits = s.components(separatedBy: NSCharacterSet.decimalDigits.inverted).reduce("") { $0 + $1 }
var r = "" var r = ""
var i = 0 var i = 0
for v in digits { // Делим каждые три цифры дефисом.
r += String(v) for v in digits {
i = i + 1 r += String(v)
if i % 3 == 0 { i = i + 1
r += "-" if i % 3 == 0 {
} r += "-"
} }
if r.hasSuffix("-") { }
r = String(r.dropLast(1)) // Исключаем дефис в конце.
} if r.hasSuffix("-") {
return r r = String(r.dropLast(1))
}
return r
} }
} }




+ 1
- 1
src/VM.swift View File

@@ -6,7 +6,7 @@ final class VM: ObservableObject {
let format = Bus.Processor( let format = Bus.Processor(
MeetupId.K.meetupIdTextUI.rawValue, MeetupId.K.meetupIdTextUI.rawValue,
MeetupId.K.meetupIdTextApp.rawValue, MeetupId.K.meetupIdTextApp.rawValue,
MeetupId.shouldFormat MeetupId.onlyFormat
) )
var subscriptions = [AnyCancellable]() var subscriptions = [AnyCancellable]()




Loading…
Cancel
Save