首页 > 解决方案 > Swift 文本字段参数

问题描述

你好我刚开始学swift,我正在尝试创建一个函数

func dataStoroge(dataStoreName:UITextField,dataStoregaForKey:String,forEntityName:String) {
    let appDelegate=UIApplication.shared.delegate as! AppDelegate
    let context=appDelegate.persistentContainer.viewContext
    
    let newUser=NSEntityDescription.insertNewObject(forEntityName: forEntityName, into: context)
    
    newUser.setValue(dataStoreName, forKey: dataStoregaForKey)
    
    
    
    do {
        
        try context.save()
        print("success")
    }
    catch{
        print("error")
    }
    
    
}

下面是我使用该功能的地方

let newUser=dataProcessors()
    newUser.dataStoroge(dataStoreName: mailTextField, dataStoregaForKey: "mail", forEntityName: "UserInformation")

我想从文本字段中获取数据,但我不知道要使用哪个参数。你能帮助我吗?

标签: swifttextfield

解决方案


推荐阅读