Михаил Капелько 10 月之前
父節點
當前提交
765889a9d6
共有 2 個檔案被更改,包括 17 行新增15 行删除
  1. +16
    -14
      src/MeetupId.swift
  2. +1
    -1
      src/VM.swift

+ 16
- 14
src/MeetupId.swift 查看文件

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

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



+ 1
- 1
src/VM.swift 查看文件

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



Loading…
取消
儲存