Uffo Uffo - 2 years ago 257
Swift Question

Swift include Files


import UIKit
class CodeAssets: NSObject {

func isValidEmail(testStr:String) -> Bool {
// print("validate calendar: \(testStr)")
let emailRegEx = "[A-Z0-9a-z._%+-][email protected][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 Source

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

let objCodeAsset = CodeAssets()
objCodeAsset.isValidEmail(testStr: "[email protected]")

In swift you just need to import the Frameworks.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download