如何将资源中的图像调用到 UIImage
我试图让用户使用 UIImage Picker 发布图像,但我也想创建一个模拟用户,通过调用一个函数来发布图片,其中参数是 UIImage 和调用该函数的用户,该函数创建一个来自 struct Post 的对象,它存储 Post 这个对象获取所需的数据,然后存储在称为 feed 的数组中。与 watchFeedview 相比,我使用 forEach 对其进行检查,并为 Postview 提供 post 对象,以便他知道要放入的数据。
mutating func makePost(image: UIImage,appUser: User) {
//guard let image = image else { return }
let post: Post = Post(ersteller: appUser, image: image, datum: "2022")
feed.append(post)
for i in 0..<friends.count {
friends[i].feed.append(post)
}
struct Post: Identifiable {
var id = UUID()
@State var ersteller: User = User()
@State var image: UIImage?
var datum: String = ""
@State var likes: Int = 0
init(ersteller: User, image: UIImage, datum: String) {
self.ersteller = ersteller
self.image = image
self.datum = datum
}
}
我认为他无法将 UIImage 提供给参数,或者无法在资产
user.makePost 中找到它(图片:UIImage(系统名称:“人”)!,appUser:用户)
i am trying to make a user Post a Image, with an UIImage Picker but i also want to make a simulate user which post a Picture by calling a function where the parameters are a UIImage and a the User who called the function the function creats a Object from the struct Post which store the data which are needed for the Post this Object get than stoared in an Array called feed. and than on the watchFeedview i go over it with an forEach and give the Postview the post object so he knows the data to put in.
mutating func makePost(image: UIImage,appUser: User) {
//guard let image = image else { return }
let post: Post = Post(ersteller: appUser, image: image, datum: "2022")
feed.append(post)
for i in 0..<friends.count {
friends[i].feed.append(post)
}
struct Post: Identifiable {
var id = UUID()
@State var ersteller: User = User()
@State var image: UIImage?
var datum: String = ""
@State var likes: Int = 0
init(ersteller: User, image: UIImage, datum: String) {
self.ersteller = ersteller
self.image = image
self.datum = datum
}
}
i Think he doesnt can give the UIImage to the parameter or dosent find it in the assets
user.makePost(image: UIImage(systemName: "person")!, appUser: user)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
制作如下内容:
UIImage(named: "imageFromAsset")
Make something like this:
UIImage(named: "imageFromAsset")