gpt4 book ai didi

ios - 表达式类型 '@lvalue String?' 在没有更多上下文的情况下不明确

转载 作者:行者123 更新时间:2023-11-28 11:26:40 25 4
gpt4 key购买 nike

无中生有我得到了这个错误表达式类型'@lvalue String?'在我的代码中没有更多上下文是模棱两可的:

    if textView.text != "" && takenImage != nil && userLocation.text != "" {
checkInternet()
// Create and save a new job
let newJob = Job(text: textView.text, jobImage: takenImage!, addedByUser: (userLabel?.text)!(-> ERROR), userImage: UserImage, location: userLocation.text, passMap: takenLocation, userID: userID, postID: key)
newJob.save()
}

我试图用其他问题的答案来解决它,但我没有让它工作......

工作类别:

var text: String = ""
var location: String = ""
var map: String?
var passMap: String?
var addedByUser: String?
var userImage: UIImage?
var jobImage: UIImage?
var downloadURL: String?
var userDownloadURL: String?
var numberOfLikes = 0
var numberOfDislikes = 0
let ref: DatabaseReference!
var userID: String?
var postID: String?


init(text: String? = nil, jobImage: UIImage? = nil, addedByUser: String? = nil, userImage: UIImage? = nil, location: String? = nil, passMap: String? = nil, userID: String? = nil, postID: String? = nil, data: [String : Any]) {
self.text = text!
self.jobImage = jobImage
self.addedByUser = addedByUser
self.userImage = userImage
self.location = location!
self.passMap = passMap
self.userID = userID
self.postID = postID
ref = Database.database().reference().child("jobs").childByAutoId()
}

最佳答案

在上面的代码中,

  1. 直接使用 userLabel?.text 而不展开任何内容。 addedByUserString? 类型。

  2. 您正在为 userImage 参数使用 UserImage 类型。请改用 UIImage 实例或 nil

  3. 您还没有在代码中添加data 参数。

这是代码,

let newJob = Job(text: textView.text, jobImage: takenImage, addedByUser: userLabel?.text, userImage: nil, location: userLocation.text, passMap: takenLocation, userID: userID, postID: key, data: [:])

避免不必要地强制展开 optionals。它可能会导致运行时异常

关于ios - 表达式类型 '@lvalue String?' 在没有更多上下文的情况下不明确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57901783/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com