diff --git a/DefaultProject.xcodeproj/project.pbxproj b/DefaultProject.xcodeproj/project.pbxproj index 4ef2a6e..fa2e61a 100644 --- a/DefaultProject.xcodeproj/project.pbxproj +++ b/DefaultProject.xcodeproj/project.pbxproj @@ -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 */; }; @@ -231,6 +232,7 @@ CA2223E82A2BCF2F005164BB /* Shimmer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Shimmer.swift; sourceTree = ""; }; CA2223EA2A2BD0F3005164BB /* Coordinator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Coordinator.swift; sourceTree = ""; }; CA2223EC2A2BD434005164BB /* Alerter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Alerter.swift; sourceTree = ""; }; + DD03D1792ABC28B100EAE138 /* test.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = test.swift; sourceTree = ""; }; DD0EA48A2A8B30FD007D8C55 /* Language.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Language.swift; sourceTree = ""; }; DD0EA48C2A8B342F007D8C55 /* ListenAndRepeatView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ListenAndRepeatView.swift; sourceTree = ""; }; DD0EA48E2A8B366A007D8C55 /* animation_human.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = animation_human.json; sourceTree = ""; }; @@ -570,6 +572,7 @@ DD72E2312A8A1233006AB647 /* SpeechRecognizer.swift */, DD0EA48A2A8B30FD007D8C55 /* Language.swift */, DD69C5D52AB9916100ADED44 /* QuizTimer.swift */, + DD03D1792ABC28B100EAE138 /* test.swift */, ); path = ViewModel; sourceTree = ""; @@ -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 */, diff --git a/DefaultProject.xcworkspace/xcuserdata/darktech4.xcuserdatad/UserInterfaceState.xcuserstate b/DefaultProject.xcworkspace/xcuserdata/darktech4.xcuserdatad/UserInterfaceState.xcuserstate index 596f6ef..f273891 100644 Binary files a/DefaultProject.xcworkspace/xcuserdata/darktech4.xcuserdatad/UserInterfaceState.xcuserstate and b/DefaultProject.xcworkspace/xcuserdata/darktech4.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/DefaultProject.xcworkspace/xcuserdata/darktech4.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/DefaultProject.xcworkspace/xcuserdata/darktech4.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index dba475d..93f6811 100644 --- a/DefaultProject.xcworkspace/xcuserdata/darktech4.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/DefaultProject.xcworkspace/xcuserdata/darktech4.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -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"> + startingLineNumber = "62" + endingLineNumber = "62" + offsetFromSymbolStart = "284"> + startingLineNumber = "62" + endingLineNumber = "62" + offsetFromSymbolStart = "340"> @@ -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"> - - - - - - diff --git a/DefaultProject/DEFAULT_SOURCE/CONTROLL_APP/CONSTANT.swift b/DefaultProject/DEFAULT_SOURCE/CONTROLL_APP/CONSTANT.swift index c4fac59..711b7f2 100644 --- a/DefaultProject/DEFAULT_SOURCE/CONTROLL_APP/CONSTANT.swift +++ b/DefaultProject/DEFAULT_SOURCE/CONTROLL_APP/CONSTANT.swift @@ -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 { @@ -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() }) } @@ -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 @@ -332,18 +331,18 @@ 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, @@ -351,35 +350,35 @@ extension CONSTANT{ 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] = [] @@ -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] = [] diff --git a/DefaultProject/ViewModel/test.swift b/DefaultProject/ViewModel/test.swift new file mode 100644 index 0000000..705d1e5 --- /dev/null +++ b/DefaultProject/ViewModel/test.swift @@ -0,0 +1,150 @@ +// +// test.swift +// DefaultProject +// +// Created by darktech4 on 20/09/2023. +// + +import SwiftUI +import Combine + +class testVMD: ObservableObject{ + @Published var count = 0 + var timer: AnyCancellable? + var arr = [1,2,3,4,5].publisher + + init() { + setUptimer() + } + + func setUptimer(){ + timer = Timer + .publish(every: 1, on: .main, in: .common) + .autoconnect() + .sink{ time in + print(time) + self.count += 1 + } + } + + +} + +struct test: View { + @StateObject var cmd = testVMD() + @State private var cancellable: AnyCancellable? + + var body: some View { + VStack{ + Text("\(formatTime(seconds: cmd.count))") + .padding(.bottom) + + Button{ + cmd.timer?.cancel() + }label: { + Text("stop") + } + .padding(.bottom) + + Button{ + cmd.setUptimer() + }label: { + Text("start") + } + } + .onAppear{ + let arr = [1,2,5,2,6,7,8] + + cancellable = arr.publisher + .sink { value in + print(value) + } + if let jsonURL = Bundle.main.url(forResource: "data", withExtension: "json") { + + var urlApi = URL(string: "https://api.github.com/repos/johnsundell/publish")! + + 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) +// +// //DATA_COLOR +// let jsonColors = json["listQuestionsColor"] +// var listColor: [QUIZ] = [] +// for (_, json) : (String, JSON) in jsonColors{ +// listColor.append(QUIZ(id: json["id"].stringValue, answer: json["answer"].stringValue, question: json["question"].stringValue, a: json["a"].stringValue, b: json["b"].stringValue, c: json["c"].stringValue, d: json["d"].stringValue, img: json["img"].stringValue)) +// } +// +// //DATA_MATH +// let jsonMath = json["listQuestionsMath"] +// var listMath: [QUIZ] = [] +// for (_, json) : (String, JSON) in jsonMath{ +// listMath.append(QUIZ(id: json["id"].stringValue, answer: json["answer"].stringValue, question: json["question"].stringValue, a: json["a"].stringValue, b: json["b"].stringValue, c: json["c"].stringValue, d: json["d"].stringValue, img: json["img"].stringValue)) +// } +// +// //DATA_LISTEN +// let jsonListen = json["listQuestionsListen"] +// var listListen: [QUIZ] = [] +// for (_, json) : (String, JSON) in jsonListen{ +// listListen.append(QUIZ(id: json["id"].stringValue, answer: json["answer"].stringValue, question: json["question"].stringValue, a: json["a"].stringValue, b: json["b"].stringValue, c: json["c"].stringValue, d: json["d"].stringValue, img: json["img"].stringValue)) +// } +// +// return QuizDataCombine(listQuestionsMath: listMath, listQuestionsColor: listColor, listQuestionsListen: listListen) +// } + .receive(on: DispatchQueue.main) + .sink( + receiveCompletion: { completion in + switch completion { + case .finished: + print("Request completed successfully.") + case .failure(let error): + print("Request failed with error: \(error)") + } + }, + receiveValue: { value in + print("Received value: \(value)") + } + ) + cancellable?.cancel() + + } + + + } + } + + func formatTime(seconds: Int) -> String { + let minutes = (seconds / 60) % 60 + let seconds = seconds % 60 + + let timeString = String(format: "%dmin %dsec", minutes, seconds) + return timeString + } + +} + +struct test_Previews: PreviewProvider { + static var previews: some View { + test() + } +} + +struct Repository: Codable { + var id: String + var name: String + var url: URL + var full_name: String + var owner: Owner +} + +struct Owner: Codable { + var id: String + var login: String + var type: String + var site_admin: Bool +} + +