冲突 AVFoundation 和 AppKit Swift
Conflict AVFoundation and AppKit Swift
我是新手,正在尝试编码Swift。这个网站非常宝贵,但现在我 运行 遇到了一个我无法找到解决方案的问题。
我正在处理视频元数据,在 Swift 中尝试同时使用 AVFoundation 和 AppKit 时遇到了一个奇怪的问题。我在 Swift 游乐场中将问题隔离如下:
此代码有效,值 "My title" 已成功分配给 testitem:
import AVFoundation
var testitem = AVMutableMetadataItem()
testitem.identifier = AVMetadataIdentifieriTunesMetadataSongName
testitem.value = "My title"
只是添加"import AppKit"语句导致错误:
import AVFoundation
import AppKit
var testitem = AVMutableMetadataItem()
testitem.identifier = AVMetadataIdentifieriTunesMetadataSongName
testitem.value = "My title"
错误:“无法分配给 'testitem' 中的 'value'。似乎不再识别 testitem 的值 属性。
这是怎么回事? AppKit 和 AVFoundation 之间是否存在一些不兼容?
顺便说一下,如果我用 import AVKit 替换 import AppKit,我会遇到同样的错误。
看来,一旦您导入 AppKit 或 AVKit,value
就会被来自 NSDictionaryControllerKeyValuePair(该导入的一部分)的函数 value()
包含在编译器的头脑中。
您可以通过调用 setValue()
轻松解决该问题,例如
testitem.setValue("My title")
请注意,您必须将 value
视为函数才能获取它,例如println(testitem.value())
.
正如您所想象的那样,这在 Objective-C 中不是问题,因为在 Objective-C 中设置 value
属性 与 相同 调用 setValue:
。但是 Swift 编译器的工作方式并不完全相同。在 Swift 中,您可以看到 getter/setter 函数或 属性 函数,但不能同时看到两者。我建议将此作为 API.
中的错误报告给 Apple
我是新手,正在尝试编码Swift。这个网站非常宝贵,但现在我 运行 遇到了一个我无法找到解决方案的问题。
我正在处理视频元数据,在 Swift 中尝试同时使用 AVFoundation 和 AppKit 时遇到了一个奇怪的问题。我在 Swift 游乐场中将问题隔离如下:
此代码有效,值 "My title" 已成功分配给 testitem:
import AVFoundation
var testitem = AVMutableMetadataItem()
testitem.identifier = AVMetadataIdentifieriTunesMetadataSongName
testitem.value = "My title"
只是添加"import AppKit"语句导致错误:
import AVFoundation
import AppKit
var testitem = AVMutableMetadataItem()
testitem.identifier = AVMetadataIdentifieriTunesMetadataSongName
testitem.value = "My title"
错误:“无法分配给 'testitem' 中的 'value'。似乎不再识别 testitem 的值 属性。
这是怎么回事? AppKit 和 AVFoundation 之间是否存在一些不兼容? 顺便说一下,如果我用 import AVKit 替换 import AppKit,我会遇到同样的错误。
看来,一旦您导入 AppKit 或 AVKit,value
就会被来自 NSDictionaryControllerKeyValuePair(该导入的一部分)的函数 value()
包含在编译器的头脑中。
您可以通过调用 setValue()
轻松解决该问题,例如
testitem.setValue("My title")
请注意,您必须将 value
视为函数才能获取它,例如println(testitem.value())
.
正如您所想象的那样,这在 Objective-C 中不是问题,因为在 Objective-C 中设置 value
属性 与 相同 调用 setValue:
。但是 Swift 编译器的工作方式并不完全相同。在 Swift 中,您可以看到 getter/setter 函数或 属性 函数,但不能同时看到两者。我建议将此作为 API.