Uffo Uffo - 19 days ago 8
Swift Question

Swift include Files

CodeAssets.swift

import UIKit
class CodeAssets: NSObject {

func isValidEmail(testStr:String) -> Bool {
// print("validate calendar: \(testStr)")
let emailRegEx = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}"

let emailTest = NSPredicate(format:"SELF MATCHES %@", emailRegEx)
return emailTest.evaluate(with: testStr)
}

}


And I have tried to include it like this:

import UIKit

class RegisterController: UIViewController, CodeAssets {


So I have made a swift class that will store some functions like validation the format of an email string, and I want to include this file in the view so I can use the function but none of the above worked.

I think I am a bit confused coming from the PHP world.

Answer

You don't need to import the file, just use it like this

let objCodeAsset = CodeAssets()
objCodeAsset.isValidEmail(testStr: "abc@gmail.com")

In swift you just need to import the Frameworks.

Comments