{"id":2419,"date":"2017-03-10T13:26:13","date_gmt":"2017-03-10T07:56:13","guid":{"rendered":"https:\/\/www.innovationm.com\/blog\/?p=2419"},"modified":"2017-03-10T13:26:13","modified_gmt":"2017-03-10T07:56:13","slug":"validation-handling-in-swift-3-0","status":"publish","type":"post","link":"https:\/\/www.innovationm.com\/blog\/validation-handling-in-swift-3-0\/","title":{"rendered":"Validation Handling in Swift 3.0"},"content":{"rendered":"<p>&nbsp;<\/p>\n<p><b><\/b><span style=\"font-weight: 400;\">User experience is the key factor for any application. Thus, More the developer is capable of delivering help, higher is the user experience. It is a mandatory for almost every application to include sign up forms,()\u2026\u2026etc.\u00a0<\/span><span style=\"font-weight: 400;\">Hence, pops up the point of validation to all these fields.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Consider a Sign up form consisting of following textfields:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Email<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Name<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Mobile no.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Maximum ten characters password<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Alpha numeric field<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Or it can be any field according to your requirement.<\/span><\/li>\n<\/ul>\n<p>There can be as many approaches you could follow to validate your set of textfields. One can do all the validations on same view controller which results in a high complexity of code. But not to worry. You are at a right place to get your set of textfields validated. Continue reading to get an approach which is much more easier to implement with no more code complexity.<\/p>\n<p><strong>How ValidationManager works?<\/strong><\/p>\n<p>The image below showing how ValidationManager in Swift 3.0 works independently of a particular view controller.<\/p>\n<p><a href=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/Screen-Shot-2017-02-10-at-11.34.47-AM.png\"><img fetchpriority=\"high\" decoding=\"async\" class=\"alignnone size-full wp-image-2569\" src=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/Screen-Shot-2017-02-10-at-11.34.47-AM.png\" alt=\"Screen Shot 2017-02-10 at 11.34.47 AM\" width=\"603\" height=\"354\" srcset=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/Screen-Shot-2017-02-10-at-11.34.47-AM.png 603w, https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/Screen-Shot-2017-02-10-at-11.34.47-AM-300x176.png 300w\" sizes=\"(max-width: 603px) 100vw, 603px\" \/><\/a><\/p>\n<p><strong>Steps:<\/strong><\/p>\n<ol>\n<li>View Controller sends textfields inputs to the struct\/class named <strong>FormvalidationModel<\/strong>.<\/li>\n<li>All the textfields input is bundles into FormValidationModel object and returns to the calling View controller.<\/li>\n<li>View Controller sends this FormValidationModel object to the <strong>ValidationManager<\/strong> for validation.<\/li>\n<li>If any error occurs like a field is empty or failed by the regular expression, ValidationManager sends error code and error message to the struct\/class named <strong>ValidationError<\/strong>.<\/li>\n<li>The error code and error message is bundled into a ValidationError object and returns to the ValidationManager.<\/li>\n<li>The ValidationManager returns the ValidationError object to the View Controller.<\/li>\n<li>View Controller shows the validation failure if validationError contains any error message and error code in the form of alert or toast as per the requirement else the form doesn&#8217;t contain any error and is ready to be Submit which is great.<\/li>\n<\/ol>\n<p>Here&#8217;s shown an example below:<\/p>\n<p><a href=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/Simulator-Screen-Shot-08-Feb-2017-4.58.25-PM.png\"><img decoding=\"async\" class=\"aligncenter wp-image-2530 size-medium\" src=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/Simulator-Screen-Shot-08-Feb-2017-4.58.25-PM-169x300.png\" alt=\"Simulator Screen Shot 08-Feb-2017, 4.58.25 PM\" width=\"169\" height=\"300\" srcset=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/Simulator-Screen-Shot-08-Feb-2017-4.58.25-PM-169x300.png 169w, https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/Simulator-Screen-Shot-08-Feb-2017-4.58.25-PM-577x1024.png 577w, https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/Simulator-Screen-Shot-08-Feb-2017-4.58.25-PM-624x1108.png 624w, https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/Simulator-Screen-Shot-08-Feb-2017-4.58.25-PM.png 640w\" sizes=\"(max-width: 169px) 100vw, 169px\" \/><\/a><\/p>\n<ol class=\"ol1\">\n<li class=\"li1\"><span class=\"s1\">On clicking Submit button after adding values to the textfields in the set of textfields for ex- signUpForm in our case, create an instance of validation model for ex- <strong>FormValidationModel<\/strong> and add values of the textfields to the model in your view Controller.<br \/>\n<\/span><\/li>\n<li class=\"li1\"><span class=\"s1\">Pass this model as a parameter to the <strong>ValidationManager<\/strong> by calling <strong>validateForm<\/strong>(<strong>signUpModel<\/strong>: FormValidationModel) function and assign the value return by this function to a variable.<br \/>\n<\/span><\/li>\n<li class=\"li1\"><span class=\"s1\">This method returns an instance of <strong>ValidationError<\/strong> which contains either nil or error values such as <strong>ErrorCode<\/strong> and <strong>ErrorMessage<\/strong>.<br \/>\n<\/span><\/li>\n<li class=\"li1\"><span class=\"s1\">Handle this validation failure on your view controller as per the requirement.<\/span><\/li>\n<\/ol>\n<p><strong>FormValidationModel.Swift<\/strong><\/p>\n<p><span style=\"font-weight: 400;\">To add this approach\u00a0to your project, first of all create a swift file with name FormValidationModel following the steps below:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Project name folder &gt;<strong> New File<\/strong> &gt; <strong>Swift File<\/strong><\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Enter name in save as field as\u00a0<strong>FormValidationModel<\/strong><\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Click on <strong>Create<\/strong><\/span><\/li>\n<\/ul>\n<p>Now open the newly created FormValidationModel class and add the code below to your file:<\/p>\n<pre class=\"lang:swift decode:true\">struct FormValidationModel {\r\n\r\n   \/\/Code\r\n}\r\n<\/pre>\n<p><span style=\"font-weight: 400;\">complete the above code by adding the following:<\/span><\/p>\n<pre class=\"lang:swift decode:true \">struct FormValidationModel {\r\n\r\n    \/\/ MARK:- VARIABLES\r\n    var email: String?\r\n    var name: String?\r\n    var mobileNo: String?\r\n    \r\n    \/\/MARK:- CONSTRUCTORS\r\n    \r\n    init(userEmail: String?, userName: String, mobile: String) {\r\n        \r\n        email = userEmail\r\n        name = userName\r\n        mobileNo = mobile\r\n    }\r\n}<\/pre>\n<p>Here we ends up with creating a FormValidationModel.Swift. The declared parameters are used to store the values of the textfields, where these values are needed to be validated further.<\/p>\n<p><span style=\"font-weight: 400;\">Now to create FormValidationModel instance, pass all the textfield\u2019s(which needs to be validated) text as a parameter to the constructor init() of the FormValidationModel struct.<\/span><\/p>\n<p><strong>ValidationError.Swift<\/strong><\/p>\n<p>Create a swift file with name ValidationError and open the newly created ValidationError file\u00a0to add the code below:<\/p>\n<pre class=\"lang:swift decode:true \">struct ValidationError {\r\n    \r\n    var errorCode: Int!\r\n    var errorString: String!\r\n    \r\n    init(code: Int, message: String) {\r\n        \r\n        errorCode = code\r\n        errorString = message\r\n    }\r\n    \r\n    struct ErrorCodes {\r\n        \r\n        static let errorCodeEmptyText = 3003\r\n        static let errorCodeInvalidAlphaNumericTest = 3006\r\n        static let errorCodeInvalidMobileNo = 3008\r\n        static let errorCodeMaxLengthExceed = 3009\r\n        static let errorCodeInvalidName = 3010\r\n        static let errorCodeInvalidEmail = 3004\r\n    }\r\n    \r\n    struct ErrorMessages {\r\n        \r\n        static let msgEmptyEmail = \"Please enter your Email Address\"\r\n        static let msgInvalidEmail = \"Please enter a valid Email Address\"\r\n        static let msgEmptyName = \"Please enter your Name\"\r\n        static let msgInvalidAlphaNumericTest = \"Please enter a valid AlphaNumeric Text\"\r\n        static let msgEmptyMobileNo = \"Please enter mobile Number\"\r\n        static let msgInvalidMobileNo = \"Please enter a valid mobile number\"\r\n        static let msgLimitedText = \"Please enter text upto the specified limit\"\r\n        static let msgInvalidName = \"Please enter a valid Name\"\r\n        static let msgEmptyText = \"Please enter the text\"\r\n    }\r\n}\r\n<\/pre>\n<p>This file contains all the error codes and error messages we need to show on validation failures on main view controller. You can add many more error codes and error messages according to your requirement.<\/p>\n<p>The constructor of the ValidationError is called every time the string validation failure occurs which accepts two parameters naming errorCode and errorMessage and returns the ValidationError model which is to be passed to the view controller by the ValidationMananger. The view controller receives either the ValidationModel with error messages and error codes or nil. If validationError is nil\u00a0that means the string validation is passed else the string validation is failed and hence we need to show the validation failure through toast or alert as per the requirement.<\/p>\n<p><strong>ValidationManager.Swift<\/strong><\/p>\n<p><span style=\"font-weight: 400;\">Now create a swift file with name ValidationManager and open the newly created ValidationManager file\u00a0to add the code below:<\/span><\/p>\n<pre class=\"lang:swift decode:true\">static private let regexEmail = \"[A-Z0-9a-z\\\\._%+-]+@([A-Za-z0-9-]+\\\\.)+[A-Za-z]{2,4}\"\r\nstatic private let regexMobNo = \"^[0-9]{6,15}$\"\r\nstatic private let regexNameType = \"^[a-zA-Z]+$\"<\/pre>\n<p><span style=\"font-weight: 400;\">The above code declares the regex string which check if the input string satisfies the regular expression or not. You can add more regex according to your requirement.<\/span><\/p>\n<p>Now add the code below to your validationManager file just after the regular expression declaration:<\/p>\n<pre class=\"lang:swift decode:true \">static func validateForm(signUpModel: FormValidationModel) -&gt; ValidationError? {\r\n        \r\n        var validationError: ValidationError? = nil\r\n        validationError = validateEmailId(email: signUpModel.email!)\r\n        if validationError != nil {\r\n            \r\n            return validationError\r\n        }\r\n        \r\n        validationError = validateNameString(string: signUpModel.name!)\r\n        if validationError != nil {\r\n            \r\n            return validationError\r\n        }\r\n        \r\n        validationError = validateMobileNumber(string: signUpModel.mobileNo!)\r\n        if validationError != nil {\r\n            \r\n            return validationError\r\n        }\r\n    }<\/pre>\n<p><span style=\"font-weight: 400;\">This method accepts a valid FormValidationModel\u00a0as a parameter and is\u00a0called from your view controller containing the set of textfields.<\/span><\/p>\n<p>Now add the following methods below the validateForm() method to validate different fields:<\/p>\n<pre class=\"lang:swift decode:true \">\/\/MARK: validate emailID\r\n    \r\n    private static func validateEmailId(email: String) -&gt; ValidationError?\r\n    {\r\n        var validationError : ValidationError? = nil\r\n        \r\n        if email == \"\"\r\n        {\r\n            validationError = ValidationError(code: ValidationError.ErrorCodes.errorCodeEmptyText, message: ValidationError.ErrorMessages.msgEmptyEmail)\r\n        }\r\n        else {\r\n            let emailTest = NSPredicate(format: stringSelfMatch, regexEmail)\r\n            let matchEmailId = emailTest.evaluate(with: email)\r\n            if(!matchEmailId)\r\n            {\r\n                validationError = ValidationError(code: ValidationError.ErrorCodes.errorCodeInvalidEmail, message: ValidationError.ErrorMessages.msgInvalidEmail)\r\n            }\r\n        }\r\n        return validationError\r\n    }\r\n    \r\n    \/\/MARK: validate Mobile number\r\n    \r\n    private static func validateMobileNumber(string: String) -&gt; ValidationError?\r\n    {\r\n        var validationError : ValidationError? = nil\r\n        if string == \"\" {\r\n            validationError = ValidationError(code: ValidationError.ErrorCodes.errorCodeEmptyText, message: ValidationError.ErrorMessages.msgEmptyMobileNo)\r\n        }\r\n        else {\r\n            \r\n            let mobileNoTest = NSPredicate(format: stringSelfMatch, regexMobNo)\r\n            let matchMobileNumber = mobileNoTest.evaluate(with: string)\r\n            if(!matchMobileNumber)\r\n            {\r\n                validationError = ValidationError(code: ValidationError.ErrorCodes.errorCodeInvalidMobileNo, message: ValidationError.ErrorMessages.msgInvalidMobileNo)\r\n            }\r\n        }\r\n        return validationError\r\n    }\r\n    \r\n    \/\/MARK: validate name\r\n    \r\n    private static func validateNameString(string: String) -&gt; ValidationError?\r\n    {\r\n        var validationError : ValidationError? = nil\r\n        if string == \"\" {\r\n            validationError = ValidationError(code: ValidationError.ErrorCodes.errorCodeEmptyText, message: ValidationError.ErrorMessages.msgEmptyName)\r\n        }\r\n        else {\r\n            \r\n            let nameTest = NSPredicate(format: stringSelfMatch, regexNameType)\r\n            let matchNameType = nameTest.evaluate(with: string)\r\n            if !matchNameType\r\n            {\r\n                validationError = ValidationError(code: ValidationError.ErrorCodes.errorCodeInvalidName, message: ValidationError.ErrorMessages.msgInvalidName)\r\n            }\r\n        }\r\n        return validationError\r\n    }<\/pre>\n<p>You can add as many methods as you need in this Manager.<\/p>\n<p>This completes the ValidationManager implemented in Swift 3.0 which can be used from any view controller where textfield validation is required.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; User experience is the key factor for any application. Thus, More the developer is capable of delivering help, higher is the user experience. It is a mandatory for almost every application to include sign up forms,()\u2026\u2026etc.\u00a0Hence, pops up the point of validation to all these fields. Consider a Sign up form consisting of following [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2828,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,71,8],"tags":[],"class_list":["post-2419","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ios","category-mobile","category-mobile-architecture-and-design"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Validation Handling in Swift 3.0 | InnovationM Blog<\/title>\n<meta name=\"description\" content=\"Learn how to handle validation in Swift 3.0 in quick steps.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.innovationm.com\/blog\/validation-handling-in-swift-3-0\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Validation Handling in Swift 3.0 | InnovationM Blog\" \/>\n<meta property=\"og:description\" content=\"Learn how to handle validation in Swift 3.0 in quick steps.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.innovationm.com\/blog\/validation-handling-in-swift-3-0\/\" \/>\n<meta property=\"og:site_name\" content=\"InnovationM - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2017-03-10T07:56:13+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/Validation-Handling.png\" \/>\n\t<meta property=\"og:image:width\" content=\"624\" \/>\n\t<meta property=\"og:image:height\" content=\"347\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"InnovationM Admin\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"InnovationM Admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/validation-handling-in-swift-3-0\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/validation-handling-in-swift-3-0\\\/\"},\"author\":{\"name\":\"InnovationM Admin\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#\\\/schema\\\/person\\\/a831bf4602d69d1fa452e3de0c8862ed\"},\"headline\":\"Validation Handling in Swift 3.0\",\"datePublished\":\"2017-03-10T07:56:13+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/validation-handling-in-swift-3-0\\\/\"},\"wordCount\":810,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/validation-handling-in-swift-3-0\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/wp-content\\\/uploads\\\/2017\\\/02\\\/Validation-Handling.png\",\"articleSection\":[\"iOS\",\"Mobile\",\"Mobile Architecture and Design\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/validation-handling-in-swift-3-0\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/validation-handling-in-swift-3-0\\\/\",\"url\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/validation-handling-in-swift-3-0\\\/\",\"name\":\"Validation Handling in Swift 3.0 | InnovationM Blog\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/validation-handling-in-swift-3-0\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/validation-handling-in-swift-3-0\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/wp-content\\\/uploads\\\/2017\\\/02\\\/Validation-Handling.png\",\"datePublished\":\"2017-03-10T07:56:13+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#\\\/schema\\\/person\\\/a831bf4602d69d1fa452e3de0c8862ed\"},\"description\":\"Learn how to handle validation in Swift 3.0 in quick steps.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/validation-handling-in-swift-3-0\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/validation-handling-in-swift-3-0\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/validation-handling-in-swift-3-0\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/wp-content\\\/uploads\\\/2017\\\/02\\\/Validation-Handling.png\",\"contentUrl\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/wp-content\\\/uploads\\\/2017\\\/02\\\/Validation-Handling.png\",\"width\":624,\"height\":347},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/validation-handling-in-swift-3-0\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Validation Handling in Swift 3.0\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/\",\"name\":\"InnovationM - Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#\\\/schema\\\/person\\\/a831bf4602d69d1fa452e3de0c8862ed\",\"name\":\"InnovationM Admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g\",\"caption\":\"InnovationM Admin\"},\"sameAs\":[\"http:\\\/\\\/www.innovationm.com\\\/\"],\"url\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/author\\\/innovationmadmin\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Validation Handling in Swift 3.0 | InnovationM Blog","description":"Learn how to handle validation in Swift 3.0 in quick steps.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.innovationm.com\/blog\/validation-handling-in-swift-3-0\/","og_locale":"en_US","og_type":"article","og_title":"Validation Handling in Swift 3.0 | InnovationM Blog","og_description":"Learn how to handle validation in Swift 3.0 in quick steps.","og_url":"https:\/\/www.innovationm.com\/blog\/validation-handling-in-swift-3-0\/","og_site_name":"InnovationM - Blog","article_published_time":"2017-03-10T07:56:13+00:00","og_image":[{"width":624,"height":347,"url":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/Validation-Handling.png","type":"image\/png"}],"author":"InnovationM Admin","twitter_misc":{"Written by":"InnovationM Admin","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.innovationm.com\/blog\/validation-handling-in-swift-3-0\/#article","isPartOf":{"@id":"https:\/\/www.innovationm.com\/blog\/validation-handling-in-swift-3-0\/"},"author":{"name":"InnovationM Admin","@id":"https:\/\/www.innovationm.com\/blog\/#\/schema\/person\/a831bf4602d69d1fa452e3de0c8862ed"},"headline":"Validation Handling in Swift 3.0","datePublished":"2017-03-10T07:56:13+00:00","mainEntityOfPage":{"@id":"https:\/\/www.innovationm.com\/blog\/validation-handling-in-swift-3-0\/"},"wordCount":810,"commentCount":0,"image":{"@id":"https:\/\/www.innovationm.com\/blog\/validation-handling-in-swift-3-0\/#primaryimage"},"thumbnailUrl":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/Validation-Handling.png","articleSection":["iOS","Mobile","Mobile Architecture and Design"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.innovationm.com\/blog\/validation-handling-in-swift-3-0\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.innovationm.com\/blog\/validation-handling-in-swift-3-0\/","url":"https:\/\/www.innovationm.com\/blog\/validation-handling-in-swift-3-0\/","name":"Validation Handling in Swift 3.0 | InnovationM Blog","isPartOf":{"@id":"https:\/\/www.innovationm.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.innovationm.com\/blog\/validation-handling-in-swift-3-0\/#primaryimage"},"image":{"@id":"https:\/\/www.innovationm.com\/blog\/validation-handling-in-swift-3-0\/#primaryimage"},"thumbnailUrl":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/Validation-Handling.png","datePublished":"2017-03-10T07:56:13+00:00","author":{"@id":"https:\/\/www.innovationm.com\/blog\/#\/schema\/person\/a831bf4602d69d1fa452e3de0c8862ed"},"description":"Learn how to handle validation in Swift 3.0 in quick steps.","breadcrumb":{"@id":"https:\/\/www.innovationm.com\/blog\/validation-handling-in-swift-3-0\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.innovationm.com\/blog\/validation-handling-in-swift-3-0\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.innovationm.com\/blog\/validation-handling-in-swift-3-0\/#primaryimage","url":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/Validation-Handling.png","contentUrl":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/Validation-Handling.png","width":624,"height":347},{"@type":"BreadcrumbList","@id":"https:\/\/www.innovationm.com\/blog\/validation-handling-in-swift-3-0\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.innovationm.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Validation Handling in Swift 3.0"}]},{"@type":"WebSite","@id":"https:\/\/www.innovationm.com\/blog\/#website","url":"https:\/\/www.innovationm.com\/blog\/","name":"InnovationM - Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.innovationm.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.innovationm.com\/blog\/#\/schema\/person\/a831bf4602d69d1fa452e3de0c8862ed","name":"InnovationM Admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g","caption":"InnovationM Admin"},"sameAs":["http:\/\/www.innovationm.com\/"],"url":"https:\/\/www.innovationm.com\/blog\/author\/innovationmadmin\/"}]}},"_links":{"self":[{"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/posts\/2419","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/comments?post=2419"}],"version-history":[{"count":0,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/posts\/2419\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/media\/2828"}],"wp:attachment":[{"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/media?parent=2419"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/categories?post=2419"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/tags?post=2419"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}