From 0c78a4f5605e593ba8fb1a02dafbbd7bd731daaf Mon Sep 17 00:00:00 2001 From: lilianeblima Date: Mon, 4 Dec 2017 16:04:09 -0200 Subject: [PATCH 1/4] Update to last version Alamofire --- Cartfile.resolved | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cartfile.resolved b/Cartfile.resolved index e873631..735eb95 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1 +1 @@ -github "Alamofire/Alamofire" "4.5.0" +github "Alamofire/Alamofire" "4.6.0" From f55ae7e9ef4859d133b4501e206f6ef741cce455 Mon Sep 17 00:00:00 2001 From: lilianeblima Date: Mon, 4 Dec 2017 16:04:23 -0200 Subject: [PATCH 2/4] Update form example --- yotpoUsageExample/ViewController.swift | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/yotpoUsageExample/ViewController.swift b/yotpoUsageExample/ViewController.swift index fc4b71b..962eb3f 100644 --- a/yotpoUsageExample/ViewController.swift +++ b/yotpoUsageExample/ViewController.swift @@ -8,13 +8,14 @@ import UIKit import yotpoKit -class ViewController: UIViewController { +class ViewController: UIViewController { + override func viewDidLoad() { super.viewDidLoad() _ = APIYotpo(appK: "appKey", clientS: "clientSecret").yotpo } - + override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. From d410b3f4ced42b0fcbcdab90ab54d315810a5fb7 Mon Sep 17 00:00:00 2001 From: lilianeblima Date: Mon, 4 Dec 2017 16:04:37 -0200 Subject: [PATCH 3/4] Update getNext question --- yotpoKit/MyQuestion.swift | 86 +++++++++++++-------------------------- 1 file changed, 29 insertions(+), 57 deletions(-) diff --git a/yotpoKit/MyQuestion.swift b/yotpoKit/MyQuestion.swift index 4640033..aac7ef4 100644 --- a/yotpoKit/MyQuestion.swift +++ b/yotpoKit/MyQuestion.swift @@ -14,10 +14,9 @@ open class MyQuestion: RequestYotpo { //Aliases to custom closures public typealias CompletionWithProductQuestions = (_ code: Int, _ msg: String, _ productQuestion: ProductQuestion?) -> Void public typealias CompletionWithQuestions = (_ code: Int, _ msg: String, _ questions: [Question]) -> Void - public typealias CompletionWithQuestionsAndExhibition = (_ code: Int, _ msg: String, - _ productQuestion: ProductQuestion, _ questionsExhibition: [QuestionExhibition]) -> Void public typealias CompletionDefault = (_ code: Int, _ msg: String) -> Void public typealias CompletionQuestion = (_ code: Int, _ title: String, _ msg: String) -> Void + public typealias CompleteNextPageQuestions = (_ msg: String, _ newQuestions: [Question], _ productQuestio: ProductQuestion) -> Void open func getQuestions(productId: String, completion: @escaping CompletionWithProductQuestions) { let endPoint = Endpoint.MyQuestion().getQuestions(productId: productId, appKey: appKey) @@ -25,25 +24,19 @@ open class MyQuestion: RequestYotpo { Alamofire.request(endPoint.URI, method: endPoint.method).responseJSON { (response) in switch response.result { case .success: - guard let JSON = response.result.value as? [String: AnyObject], - let code = JSON["status"]?["code"] as? Int, - let message = JSON["status"]?["message"] as? String else { + guard let JSON = response.result.value as? [String: AnyObject] else { completion(GetMessage.ParsingError.code, GetMessage.ParsingError.msg, nil) return } - if code == 200 { - guard let questionDict = JSON["response"] as? [String: AnyObject] else { - completion(GetMessage.ParsingError.code, GetMessage.ParsingError.msg, nil) - return - } - - let productQ = ProductQuestion(dic: questionDict) - completion(code, message, productQ) - - } else { - completion(code, message, nil) + guard let questionDict = JSON["response"] as? [String: AnyObject] else { + completion(GetMessage.ParsingError.code, GetMessage.ParsingError.msg, nil) + return } + + let productQ = ProductQuestion(dic: questionDict) + completion(0, "OK", productQ) + case .failure: completion(GetMessage.InternetError.code, GetMessage.InternetError.msg, nil) } @@ -57,24 +50,19 @@ open class MyQuestion: RequestYotpo { switch response.result { case .success: guard let JSON = response.result.value as? [String: AnyObject], - let code = JSON["status"]?["code"] as? Int, let message = JSON["status"]?["message"] as? String else { completion(GetMessage.ParsingError.code, GetMessage.ParsingError.msg, []) return } - - if code == 200 { - guard let questionDict = JSON["response"] as? [String: AnyObject] else { - completion(GetMessage.ParsingError.code, GetMessage.ParsingError.msg, []) - return - } - - let productQ = ProductQuestion(dic: questionDict) - completion(code, message, productQ.questions) - - } else { - completion(code, message, []) + + guard let questionDict = JSON["response"] as? [String: AnyObject] else { + completion(GetMessage.ParsingError.code, GetMessage.ParsingError.msg, []) + return } + + let productQ = ProductQuestion(dic: questionDict) + completion(200, message, productQ.questions) + case .failure: completion(GetMessage.InternetError.code, GetMessage.InternetError.msg, []) } @@ -175,41 +163,25 @@ open class MyQuestion: RequestYotpo { } } - - open func getNextQuestions(productQuestion: ProductQuestion, - oldQuestionsExhibition: [QuestionExhibition], productId: String, - completion: @escaping CompletionWithQuestionsAndExhibition) { - let myOldProductQuestion = productQuestion.questions.filter { (question) -> Bool in + + open func getNextQuestion(currentQuestion: ProductQuestion, productId: String, completion: @escaping CompleteNextPageQuestions) { + let questions = currentQuestion.questions.filter { (question) -> Bool in return question.id != 0 } - var newProductQuestion = productQuestion - if productQuestion.totalQuestions > myOldProductQuestion.count { - let currentPage = myOldProductQuestion.count/5 - var questionsExhibition = [QuestionExhibition]() - getQuestionPerPage(productId: productId, page: currentPage+1, completion: { (code, msg, result) in - newProductQuestion.questions += result + var newProductQuestion = currentQuestion + + if currentQuestion.totalQuestions > questions.count { + let currentPage = questions.count/5 + + getQuestionPerPage(productId: productId, page: currentPage+1, completion: { (_, _, newQuestions) in - for question in result { - let questExhibition = QuestionExhibition(withQuestion: question) - - let isContain = oldQuestionsExhibition.contains(where: { (questionEx) -> Bool in - return questionEx.idQuestion == questExhibition.idQuestion && questionEx.idAnswer == questExhibition.idAnswer && - questionEx.typeQuestion == questExhibition.typeQuestion - }) - if !isContain { - questionsExhibition.append(questExhibition) - for answer in question.answers { - let answerExhibition = QuestionExhibition(withAnswer: answer, idQuest: question.id) - questionsExhibition.append(answerExhibition) - } - } - } + newProductQuestion.questions += newQuestions - completion(code, msg, newProductQuestion, questionsExhibition) + completion("Sucess", newQuestions, newProductQuestion) }) } else { - completion(2, "There aren't questions to download", newProductQuestion, []) + completion("There aren't questions to download", [], currentQuestion) } } From caaabf6810dd5c9d8c5db59125fef71d7f4786e6 Mon Sep 17 00:00:00 2001 From: lilianeblima Date: Mon, 4 Dec 2017 16:09:11 -0200 Subject: [PATCH 4/4] Update to swift 4 --- yotpoKit.xcodeproj/project.pbxproj | 43 ++++++++++++++----- .../xcshareddata/xcschemes/yotpoKit.xcscheme | 4 +- 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/yotpoKit.xcodeproj/project.pbxproj b/yotpoKit.xcodeproj/project.pbxproj index 0501573..942b032 100644 --- a/yotpoKit.xcodeproj/project.pbxproj +++ b/yotpoKit.xcodeproj/project.pbxproj @@ -429,13 +429,13 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0830; - LastUpgradeCheck = 0830; + LastUpgradeCheck = 0910; ORGANIZATIONNAME = "Liliane Lima"; TargetAttributes = { FB7575DE1E9D08CC00D1E844 = { CreatedOnToolsVersion = 8.3; DevelopmentTeam = PFQ8633X58; - LastSwiftMigration = 0830; + LastSwiftMigration = 0910; ProvisioningStyle = Automatic; }; FB7575E71E9D08CC00D1E844 = { @@ -446,17 +446,20 @@ FB92FB941E9E646A00D9B127 = { CreatedOnToolsVersion = 8.3; DevelopmentTeam = PFQ8633X58; + LastSwiftMigration = 0910; ProvisioningStyle = Automatic; }; FB92FBA71E9E646A00D9B127 = { CreatedOnToolsVersion = 8.3; DevelopmentTeam = PFQ8633X58; + LastSwiftMigration = 0910; ProvisioningStyle = Automatic; TestTargetID = FB92FB941E9E646A00D9B127; }; FB92FBB21E9E646A00D9B127 = { CreatedOnToolsVersion = 8.3; DevelopmentTeam = PFQ8633X58; + LastSwiftMigration = 0910; ProvisioningStyle = Automatic; TestTargetID = FB92FB941E9E646A00D9B127; }; @@ -654,7 +657,9 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_DOCUMENTATION_COMMENTS = YES; @@ -662,7 +667,11 @@ CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -709,7 +718,9 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_DOCUMENTATION_COMMENTS = YES; @@ -717,7 +728,11 @@ CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -770,7 +785,8 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -796,7 +812,8 @@ PRODUCT_BUNDLE_IDENTIFIER = amaro.yotpoKit; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_VERSION = 4.0; }; name = Release; }; @@ -839,7 +856,8 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = amaro.yotpoUsageExample; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -856,7 +874,8 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = amaro.yotpoUsageExample; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_VERSION = 4.0; }; name = Release; }; @@ -870,7 +889,8 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = amaro.yotpoUsageExampleTests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/yotpoUsageExample.app/yotpoUsageExample"; }; name = Debug; @@ -885,7 +905,8 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = amaro.yotpoUsageExampleTests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/yotpoUsageExample.app/yotpoUsageExample"; }; name = Release; @@ -899,7 +920,8 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = amaro.yotpoUsageExampleUITests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.0; TEST_TARGET_NAME = yotpoUsageExample; }; name = Debug; @@ -913,7 +935,8 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = amaro.yotpoUsageExampleUITests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.0; TEST_TARGET_NAME = yotpoUsageExample; }; name = Release; diff --git a/yotpoKit.xcodeproj/xcshareddata/xcschemes/yotpoKit.xcscheme b/yotpoKit.xcodeproj/xcshareddata/xcschemes/yotpoKit.xcscheme index 76c9087..e50b301 100644 --- a/yotpoKit.xcodeproj/xcshareddata/xcschemes/yotpoKit.xcscheme +++ b/yotpoKit.xcodeproj/xcshareddata/xcschemes/yotpoKit.xcscheme @@ -1,6 +1,6 @@