【发布时间】:2014-08-06 15:17:54
【问题描述】:
从历史上看,在将 imageView 中的图像与使用 [UIImage imageNamed:] 的某些预定义图像进行比较时,我已经成功地使用了 == 比较器。这是因为我在使用相同的文件名重复调用[UIImage imageNamed:]时收到相同的对象,例如:
(lldb) po [UIImage imageNamed:@"foo.png"]
<UIImage: 0x7a1433a0>
(lldb) po [UIImage imageNamed:@"foo.png"]
<UIImage: 0x7a1433a0>
(lldb) po [UIImage imageNamed:@"foo.png"]
<UIImage: 0x7a1433a0>
使用 Xcode 6 Beta 4,在尝试将 imageView 中的图像与预期图像进行比较时,我的许多单元测试都失败了,这似乎是因为我获得了具有给定文件名的唯一图像实例每次,而不是上面解释的旧行为。在 Xcode 6 Beta 4 中做同样的事情时,我得到了这个:
(lldb) po [UIImage imageNamed:@"foo.png"]
<UIImage: 0x7a691f00>
(lldb) po [UIImage imageNamed:@"foo.png"]
<UIImage: 0x7a6a1d00>
(lldb) po [UIImage imageNamed:@"foo.png"]
<UIImage: 0x7a1f3230>
(lldb) po [UIImage imageNamed:@"foo.png"]
<UIImage: 0x7a6a1fd0>
这是预期的行为,我在 UIImage 的文档中缺少的东西,也许是我应该以不同方式解决的实现问题,还是我应该将其作为错误提交给 Apple?有什么见解吗?
【问题讨论】:
-
你是用什么 iOS 版本构建的?
-
在 Xcode 5 中它是 7.1,我必须检查一下,但我假设它在测试版中是 8.0。
-
在 iOS 7.1 中它对我来说正常工作,不一致仅在 iOS 8 中出现
标签: ios objective-c uiimage xcode6 imagenamed