Skip to content

Commit

Permalink
optional combine
Browse files Browse the repository at this point in the history
  • Loading branch information
xqsadness committed Sep 21, 2023
1 parent 784f17b commit a53fed1
Show file tree
Hide file tree
Showing 5 changed files with 211 additions and 90 deletions.
4 changes: 4 additions & 0 deletions DefaultProject.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
CA2223EB2A2BD0F3005164BB /* Coordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = CA2223EA2A2BD0F3005164BB /* Coordinator.swift */; };
CA2223ED2A2BD434005164BB /* Alerter.swift in Sources */ = {isa = PBXBuildFile; fileRef = CA2223EC2A2BD434005164BB /* Alerter.swift */; };
DA475ADEA3BDD29E30F2BF97 /* Pods_DefaultProject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 42865764303805AED8FF6CB0 /* Pods_DefaultProject.framework */; };
DD03D17A2ABC28B100EAE138 /* test.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD03D1792ABC28B100EAE138 /* test.swift */; };
DD0EA48B2A8B30FD007D8C55 /* Language.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD0EA48A2A8B30FD007D8C55 /* Language.swift */; };
DD0EA48D2A8B342F007D8C55 /* ListenAndRepeatView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD0EA48C2A8B342F007D8C55 /* ListenAndRepeatView.swift */; };
DD0EA4902A8B366B007D8C55 /* animation_human.json in Resources */ = {isa = PBXBuildFile; fileRef = DD0EA48E2A8B366A007D8C55 /* animation_human.json */; };
Expand Down Expand Up @@ -231,6 +232,7 @@
CA2223E82A2BCF2F005164BB /* Shimmer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Shimmer.swift; sourceTree = "<group>"; };
CA2223EA2A2BD0F3005164BB /* Coordinator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Coordinator.swift; sourceTree = "<group>"; };
CA2223EC2A2BD434005164BB /* Alerter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Alerter.swift; sourceTree = "<group>"; };
DD03D1792ABC28B100EAE138 /* test.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = test.swift; sourceTree = "<group>"; };
DD0EA48A2A8B30FD007D8C55 /* Language.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Language.swift; sourceTree = "<group>"; };
DD0EA48C2A8B342F007D8C55 /* ListenAndRepeatView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ListenAndRepeatView.swift; sourceTree = "<group>"; };
DD0EA48E2A8B366A007D8C55 /* animation_human.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = animation_human.json; sourceTree = "<group>"; };
Expand Down Expand Up @@ -570,6 +572,7 @@
DD72E2312A8A1233006AB647 /* SpeechRecognizer.swift */,
DD0EA48A2A8B30FD007D8C55 /* Language.swift */,
DD69C5D52AB9916100ADED44 /* QuizTimer.swift */,
DD03D1792ABC28B100EAE138 /* test.swift */,
);
path = ViewModel;
sourceTree = "<group>";
Expand Down Expand Up @@ -869,6 +872,7 @@
CA2223C02A2BB34A005164BB /* Triangle.swift in Sources */,
DD72E2322A8A1233006AB647 /* SpeechRecognizer.swift in Sources */,
DD72E2382A8A1D4D006AB647 /* HistoryView.swift in Sources */,
DD03D17A2ABC28B100EAE138 /* test.swift in Sources */,
CA22239D2A2BB34A005164BB /* CircleProgressView.swift in Sources */,
278982FE2A84EE65003CB639 /* CreateUsernameView.swift in Sources */,
CA2223A52A2BB34A005164BB /* InterstitialAd.swift in Sources */,
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
filePath = "DefaultProject/DEFAULT_SOURCE/CONTROLL_APP/CONSTANT.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "63"
endingLineNumber = "63"
startingLineNumber = "62"
endingLineNumber = "62"
landmarkName = "loadData(_:)"
landmarkType = "7">
<Locations>
<Location
uuid = "6D186499-383D-4553-9F43-0F0D52EFD085 - 70ba66d3b96d59c"
uuid = "6D186499-383D-4553-9F43-0F0D52EFD085 - 70ba66d3b96d47d"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
Expand All @@ -30,24 +30,24 @@
urlString = "file:///Users/darktech4/QuizKid/DefaultProject/DEFAULT_SOURCE/CONTROLL_APP/CONSTANT.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "63"
endingLineNumber = "63"
offsetFromSymbolStart = "560">
startingLineNumber = "62"
endingLineNumber = "62"
offsetFromSymbolStart = "284">
</Location>
<Location
uuid = "6D186499-383D-4553-9F43-0F0D52EFD085 - bc563ae47193a895"
uuid = "6D186499-383D-4553-9F43-0F0D52EFD085 - 70ba66d3b96d47d"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "closure #1 () -&gt; () in closure #1 (__C.FIRDataSnapshot) -&gt; () in DefaultProject.CONSTANT.loadData(() -&gt; ()) -&gt; ()"
symbolName = "closure #1 (__C.FIRDataSnapshot) -&gt; () in DefaultProject.CONSTANT.loadData(() -&gt; ()) -&gt; ()"
moduleName = "DefaultProject"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/darktech4/QuizKid/DefaultProject/DEFAULT_SOURCE/CONTROLL_APP/CONSTANT.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "64"
endingLineNumber = "64"
offsetFromSymbolStart = "48">
startingLineNumber = "62"
endingLineNumber = "62"
offsetFromSymbolStart = "340">
</Location>
</Locations>
</BreakpointContent>
Expand All @@ -62,42 +62,10 @@
filePath = "DefaultProject/DEFAULT_SOURCE/CONTROLL_APP/CONSTANT.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "70"
endingLineNumber = "70"
startingLineNumber = "69"
endingLineNumber = "69"
landmarkName = "loadData(_:)"
landmarkType = "7">
<Locations>
<Location
uuid = "6FD388C0-50AA-4843-A795-6C62C17947D2 - 37b0f4f70749a51c"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "DefaultProject.CONSTANT.loadData(() -&gt; ()) -&gt; ()"
moduleName = "DefaultProject"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/darktech4/QuizKid/DefaultProject/DEFAULT_SOURCE/CONTROLL_APP/CONSTANT.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "70"
endingLineNumber = "70"
offsetFromSymbolStart = "1548">
</Location>
<Location
uuid = "6FD388C0-50AA-4843-A795-6C62C17947D2 - aa6e787a29110f68"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "closure #2 () -&gt; () in DefaultProject.CONSTANT.loadData(() -&gt; ()) -&gt; ()"
moduleName = "DefaultProject"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/darktech4/QuizKid/DefaultProject/DEFAULT_SOURCE/CONTROLL_APP/CONSTANT.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "71"
endingLineNumber = "71"
offsetFromSymbolStart = "48">
</Location>
</Locations>
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
Expand All @@ -110,8 +78,8 @@
filePath = "DefaultProject/DEFAULT_SOURCE/CONTROLL_APP/CONSTANT.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "371"
endingLineNumber = "371"
startingLineNumber = "370"
endingLineNumber = "370"
landmarkName = "pareDataCombine(_:completions:)"
landmarkType = "7">
</BreakpointContent>
Expand Down
85 changes: 42 additions & 43 deletions DefaultProject/DEFAULT_SOURCE/CONTROLL_APP/CONSTANT.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ class CONSTANT{
completion()
})
}
}
else {
} else {
if let manifestPath = Bundle.main.path(forResource: "temp_manifest", ofType: "json"){
if let data = NSData(contentsOfFile: manifestPath) {
do {
Expand All @@ -60,14 +59,14 @@ class CONSTANT{
return
}
let json = JSON(snapshot.value as Any)
self.pareData(json, completion: {
self.parseData(json, completion: {
completion()
})
}
}
else {
if let manifestPath = Bundle.main.url(forResource: "data", withExtension: "json"){
self.pareDataCombine(manifestPath, completions: {
self.parseDataCombine(manifestPath, completions: {
completion()
})
}
Expand Down Expand Up @@ -314,14 +313,14 @@ extension CONSTANT{
}

//data
func pareData(_ json: JSON, completion: @escaping ()->Void){
self.parseJson(json: json) { data in
func parseData(_ json: JSON, completion: @escaping ()->Void){
self.parseSwiftyJson(json: json) { data in
self.DATA_COLOR = data.listQuestionsColor

self.DATA_HISTORY = data.listQuestionsHistory

self.DATA_LISTEN = data.listQuestionsListen

self.DATA_MATH = data.listQuestionsMath

self.DATA_SURROUNDING = data.listQuestionsSurrounding
Expand All @@ -332,54 +331,54 @@ extension CONSTANT{
}
}

func pareDataCombine(_ jsonURL: URL, completions: @escaping ()->Void){
let publisher = URLSession.shared.dataTaskPublisher(for: jsonURL)
cancellable = publisher
.map(\.data)
func parseDataCombine(_ jsonURL: URL, completions: @escaping ()->Void){
let publisher = URLSession.shared.dataTaskPublisher(for: jsonURL)

cancellable = publisher
.map(\.data)
// .decode(type: QUIZ.self, decoder: JSONDecoder())
.tryMap { data -> QuizDataCombine in
let json = try JSON(data: data)
var save: QuizDataCombine?
self.parseJson(json: json){ data in
save = QuizDataCombine(
.tryMap { data -> QuizDataCombine in
let json = try JSON(data: data)
var save: QuizDataCombine?

self.parseSwiftyJson(json: json){ data in
save = QuizDataCombine(
listQuestionsMath: data.listQuestionsMath,
listQuestionsColor: data.listQuestionsMath,
listQuestionsListen: data.listQuestionsMath,
listQuestionsSurrounding: data.listQuestionsSurrounding,
listQuestionsHistory: data.listQuestionsHistory,
listListenAndRepeat: data.listListenAndRepeat,
listWriting: data.listWriting
)
}
return save!
}
.receive(on: DispatchQueue.main)
.sink(
)
}
return save ?? .init(listQuestionsMath: [], listQuestionsColor: [], listQuestionsListen: [], listQuestionsSurrounding: [], listQuestionsHistory: [], listListenAndRepeat: [], listWriting: [])
}
.receive(on: DispatchQueue.main)
.sink(
receiveCompletion: { completion in
switch completion {
case .finished:
print("Request completed successfully.")
print("Request completed successfully.")
completions()
case .failure(let error):
print("Request failed with error: \(error)")
case .failure(let error):
print("Request failed with error: \(error)")
completions()
}
},
receiveValue: { value in
self.DATA_MATH = value.listQuestionsMath
self.DATA_HISTORY = value.listQuestionsHistory
self.DATA_COLOR = value.listQuestionsColor
self.DATA_LISTEN = value.listQuestionsListen
self.DATA_SURROUNDING = value.listQuestionsSurrounding
self.DATA_LISTEN_AND_REPEAT = value.listListenAndRepeat
self.DATA_WRITING = value.listWriting
}
)
}
}
},
receiveValue: { value in
self.DATA_MATH = value.listQuestionsMath
self.DATA_HISTORY = value.listQuestionsHistory
self.DATA_COLOR = value.listQuestionsColor
self.DATA_LISTEN = value.listQuestionsListen
self.DATA_SURROUNDING = value.listQuestionsSurrounding
self.DATA_LISTEN_AND_REPEAT = value.listListenAndRepeat
self.DATA_WRITING = value.listWriting
}
)
}

func parseJson(json: JSON, completion: @escaping (QuizDataCombine) -> Void){
func parseSwiftyJson(json: JSON, completion: @escaping (QuizDataCombine) -> Void){

let jsonColors = json["listQuestionsColor"]
var listColor: [QUIZ] = []
Expand Down Expand Up @@ -421,7 +420,7 @@ extension CONSTANT{
for (_, json) : (String, JSON) in jsonWriting{
listWriting.append(QUIZ(id: json["id"].stringValue, answer: json["answer"].stringValue, question: json["question"].stringValue))
}

//DATA_listenRepeat
let jsonRepeat = json["listListenAndRepeat"]
var listListenRepeat: [QUIZ] = []
Expand Down
Loading

0 comments on commit a53fed1

Please sign in to comment.