Skip to content

Commit

Permalink
[#4] Person Model 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
ezidayzi committed Sep 24, 2021
1 parent 67882e3 commit c679118
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 6 deletions.
65 changes: 65 additions & 0 deletions CheoMooRac/CheoMooRac/Sources/Managers/StringManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,68 @@ struct StringManager {
return hangul[Int(index)]
}
}

extension CharacterSet{
static var modernHangul: CharacterSet{
return CharacterSet(charactersIn: ("".unicodeScalars.first!)...("".unicodeScalars.first!))
}
}

public class Jamo {

// UTF-8 기준
static let INDEX_HANGUL_START:UInt32 = 44032 // "가"
static let INDEX_HANGUL_END:UInt32 = 55199 // "힣"

static let CYCLE_CHO :UInt32 = 588
static let CYCLE_JUNG :UInt32 = 28

static let CHO = [
"","","","","","","","","","",
"","","","","","","","",""
]

static let JUNG = [
"", "", "", "", "", "","", "", "", "",
"", "","", "", "", "", "", "", "", "",
""
]

static let JONG = [
"","","","","","","","","","",
"","","","","","","","","","",
"","","","","","","",""
]

static let JONG_DOUBLE = [
"":"ㄱㅅ","":"ㄴㅈ","":"ㄴㅎ","":"ㄹㄱ","":"ㄹㅁ",
"":"ㄹㅂ","":"ㄹㅅ","":"ㄹㅌ","":"ㄹㅍ","":"ㄹㅎ",
"":"ㅂㅅ"
]

// 주어진 "단어"를 자모음으로 분해해서 리턴하는 함수
class func getJamo(_ input: String) -> String {
var jamo = ""
//let word = input.trimmingCharacters(in: .whitespacesAndNewlines).trimmingCharacters(in: .punctuationCharacters)
for scalar in input.unicodeScalars{
jamo += getJamoFromOneSyllable(scalar) ?? ""
}
return jamo
}

// 주어진 "코드의 음절"을 자모음으로 분해해서 리턴하는 함수
private class func getJamoFromOneSyllable(_ n: UnicodeScalar) -> String?{
if CharacterSet.modernHangul.contains(n){
let index = n.value - INDEX_HANGUL_START
let cho = CHO[Int(index / CYCLE_CHO)]
let jung = JUNG[Int((index % CYCLE_CHO) / CYCLE_JUNG)]
var jong = JONG[Int(index % CYCLE_JUNG)]
if let disassembledJong = JONG_DOUBLE[jong] {
jong = disassembledJong
}
return cho + jung + jong
}else{
return String(UnicodeScalar(n))
}
}
}
34 changes: 28 additions & 6 deletions CheoMooRac/CheoMooRac/Sources/ViewModels/MainViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ protocol MainViewModelInput {
}

protocol MainViewModelOutput {
var list: Dynamic<[String]> {get}
var list: Dynamic<[Person]> {get}
var sectionHeaderList: Dynamic<[String]> {get}
var nowRefreshing: Dynamic<Bool> {get}
var sectionArray: Dynamic<[String]> {get}
Expand All @@ -33,26 +33,48 @@ class MainViewModel: MainViewModelProtocol {


// MARK: - OUTPUT
let list: Dynamic<[String]> = Dynamic([])
let list: Dynamic<[Person]> = Dynamic([])
let sectionHeaderList: Dynamic<[String]> = Dynamic([])
let nowRefreshing: Dynamic<Bool> = Dynamic(false)
let sectionArray: Dynamic<[String]> = Dynamic([])

func getSectionArray(at section: Int) -> Dynamic<[String]> {

let list$ = self.list.value.filter {
return StringManager.shared.chosungCheck(word: $0) == sectionHeaderList.value[section-1]
return StringManager.shared.chosungCheck(word: $0.familyName + $0.firstName) == sectionHeaderList.value[section-1]
}.map { person in
return person.familyName + person.firstName
}

return Dynamic(list$)
}


init() {
self.list.value = ["김윤서", "김루희", "윤예지", "김혜수", "코코", "민재", "잼권이", "리헤이", "노제", "몬익화", "립제이", "잘린이", "엠마", "모아나", "케이데이", "가비", "시미즈zz", "강호동", "이수근", "유재석", "리정" ]
self.list.value = [Person(firstName: "윤서", familyName: "", phoneNumber: "010-6515-6030"),
Person(firstName: "루희", familyName: "", phoneNumber: "010-6515-6030"),
Person(firstName: "예지", familyName: "", phoneNumber: "010-6515-6030"),
Person(firstName: "혜수", familyName: "", phoneNumber: "010-6515-6030"),
Person(firstName: "리헤이", familyName: "", phoneNumber: "010-6515-6030"),
Person(firstName: "", familyName: "", phoneNumber: "010-6515-6030"),
Person(firstName: "엠마", familyName: "", phoneNumber: "010-6515-6030"),
Person(firstName: "모아나", familyName: "", phoneNumber: "010-6515-6030"),
Person(firstName: "민재", familyName: "", phoneNumber: "010-6515-6030"),
Person(firstName: "케이데이", familyName: "", phoneNumber: "010-6515-6030"),
Person(firstName: "가비", familyName: "", phoneNumber: "010-6515-6030"),
Person(firstName: "시미즈", familyName: "", phoneNumber: "010-6515-6030"),
Person(firstName: "호동", familyName: "", phoneNumber: "010-6515-6030"),
Person(firstName: "재석", familyName: "", phoneNumber: "010-6515-6030"),
Person(firstName: "리정", familyName: "", phoneNumber: "010-6515-6030"),
Person(firstName: "몬익화", familyName: "", phoneNumber: "010-6515-6030"),
Person(firstName: "코코", familyName: "", phoneNumber: "010-6515-6030"),
Person(firstName: "잼권", familyName: "", phoneNumber: "010-6515-6030")

]

var sectionHeaderList$: [String] = []
self.list.value.forEach { name in
sectionHeaderList$.append(StringManager.shared.chosungCheck(word: name))
self.list.value.forEach { person in
sectionHeaderList$.append(StringManager.shared.chosungCheck(word: person.familyName + person.firstName))
}

self.sectionHeaderList.value = Array(Set(sectionHeaderList$)).sorted()
Expand Down

0 comments on commit c679118

Please sign in to comment.