gpt4 book ai didi

uiimage - 从 AnyObject 向下转换为 UIImage[] - Swift

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

我正在尝试将 valueForKeyPath 的结果转换为 UIImage 数组。尝试这样做时,我遇到了这个错误

Undefined symbols for architecture i386: "TToFC9TableView19TableViewControllers6photosGSqGSaCSo7UIImage", referenced from: __TFC9TableView29JustPostedTableViewController11fetchPhotosfS0_FT_T_ in JustPostedTableViewController.o ld: symbol(s) not found for architecture i386 clang: error: linker command failed with exit code 1 (use -v to see invocation)

这是我对 swift 代码的尝试:propertyListResults是一个NSDictionary,valueForKeyPath中的参数是一个String

var photos : AnyObject = (propertyListResults as AnyObject).valueForKeyPath(flickrFetcher.FLICKR_RESULTS_PHOTOS)

self.photos = photos as? UIImage[]

代码的工作 Objective-C 版本是

NSArray *photos = [propertyListResults valueForKeyPath:FLICKR_RESULTS_PHOTOS];
self.photos = photos

最佳答案

如果你在 "__TToFC9TableView19TableViewControllers6photosGSqGSaCSo7UIImage__" 上运行 swift-demangle,你会得到:

@objc TableView.TableViewController.photos.setter : (ObjectiveC.UIImage[])?

这意味着链接器没有在 TableViewController 上找到照片的 setter。看来您使用的是 TableViewController 而不是您自己的具有 photos 属性的子类。

还有,照片是? UIImage[] 返回一个 Optional,因为它有可能失败。您应该执行以下操作:

if let images : [UIImage] = photos as? [UIImage] {
self.photos = images
}

这会检查 photos 是否可以转换为 [UIImage]。如果可以,它会将其分配给 self.photos

编辑:将 UIImage 数组语法更新为 beta 3 中的新数组语法

关于uiimage - 从 AnyObject 向下转换为 UIImage[] - Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24355837/

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