ios - swift 包含文件

标签 ios swift

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)
 }

}

我试过像这样包含它:

import UIKit

class RegisterController: UIViewController, CodeAssets {

所以我创建了一个 swift 类,它将存储一些函数,例如验证电子邮件字符串的格式,我想在 View 中包含此文件,以便我可以使用该函数,但以上均无效。

我觉得我对 PHP 世界有点困惑。

最佳答案

无需导入文件,直接使用即可

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

在 swift 中,您只需要导入框架。

关于ios - swift 包含文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40636545/

相关文章:

ios - 类型 'UIView' 的值没有成员 'image'

ios - 如何判断 CLLocationManager 何时锁定​​了用户位置

ios - 如何将标题从 UIAlertAction 发送到另一个 UIViewController 作为该 VC 的标题

ios - 将数组从 1 个 View Controller 发送到 2 个其他单独的 View Controller

在 textview 或标签周围快速绘制边框

ios - AFNetworking AFHTTPClient 成功和失败的不同内容类型

ios - NavigationController 更改后退按钮

ios - WebRTC iOS : Record Remote Audio stream using WebRTC

ios - 基于 5.0 SDK 构建的 iOS 应用程序可以在 iOS 4.3 上运行吗?

ios - NavigationBar 后退按钮在 popViewController 之后更改文本