gpt4 book ai didi

swift3 - 无法比较 Swift 3 中的 AnyHashable

转载 作者:行者123 更新时间:2023-12-01 13:40:40 24 4
gpt4 key购买 nike

我有一个由 XCDYoutubeKit pod 在 swift projet 中返回的字典数组:

print(video?.streamURLs ?? "nothing to print")


[AnyHashable(17): https://r7---sn-8vv-cg0l.googlevideo.com/videoplayback?source=youtube&pcm2cms=yes&pl=20&mv=m&initcwndbps=2522500&ipbits=0&ms=au&key=yt6&signature=373890DBE71537EB460B6D5E0C6D6B11066DAAC7.6E0898B1C97F6504432B4A2E96511203B86AFF89&mime=video%2F3gpp&ip=212.68.230.6&dur=275.388&id=o-AALDaM6KxpA6-UX-Zfhcy0MYtZSEWxj3HGfu-aPvZR5z&upn=Wolarcf9l8k&mt=1478956785&mn=sn-8vv-cg0l&itag=17&requiressl=yes&expire=1478978548&lmt=1394298238781402&mm=31&sparams=dur%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Clmt%2Cmime%2Cmm%2Cmn%2Cms%2Cmv%2Cpcm2cms%2Cpl%2Crequiressl%2Csource%2Cupn%2Cexpire&ratebypass=yes, AnyHashable(135): https://r7---sn-8vv-cg0l.googlevideo.com/videoplayback?pl=20&initcwndbps=2522500&ipbits=0&key=yt6&ip=212.68.230.6&upn=IqqzaXYA2Ag&expire=1478978548&lmt=1458192852355410&mm=31&clen=26845311&source=youtube&pcm2cms=yes&mv=m&mt=1478956785&ms=au&mn=sn-8vv-cg0l&mime=video%2Fmp4&gir=yes&dur=275.008&id=o-AALDaM6KxpA6-UX-Zfhcy0MYtZSEWxj3HGfu-aPvZR5z&signature=86328F117AEF617380C2EE4C0327891683F8571A.C57F883610B44498FEBDF556868860687223BDF2&itag=135&requiressl=yes&sparams=clen%2Cdur%2Cgir%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Clmt%2Cmime%2Cmm%2Cmn%2Cms%2Cmv%2Cpcm2cms%2Cpl%2Crequiressl%2Csource%2Cupn%2Cexpire&ratebypass=yes]

我正在尝试比较键,但我遇到了一些看起来非常简单的事情......我已经尝试过:

                for item in (video?.streamURLs)! {

if item.key == AnyHashable(UInt(17)) {
//never pass here
print(item.key)
}
}

我不熟悉新的 AnyHashable 类型,但据我了解,它应该允许 == 运算符。 Apple doc

非常感谢任何帮助,谢谢!

最佳答案

这是 AnyHashable 中的一个错误,acknowledged by Joe Groff, Swift engineer :

@0xced Looks like the bug is in AnyHashable. If it's possible to type your dictionary to NSDictionary, that might work around

在 Swift 3 中,您必须显式使用 NSNumber 来访问 streamURLs 字典中的值。

struct YouTubeVideoQuality {
static let hd720 = NSNumber(value: XCDYouTubeVideoQuality.HD720.rawValue)
static let medium360 = NSNumber(value: XCDYouTubeVideoQuality.medium360.rawValue)
static let small240 = NSNumber(value: XCDYouTubeVideoQuality.small240.rawValue)
}

func playVideo(videoIdentifier: String?) {
let playerViewController = AVPlayerViewController()
self.present(playerViewController, animated: true, completion: nil)

XCDYouTubeClient.default().getVideoWithIdentifier(videoIdentifier) { [weak playerViewController] (video: XCDYouTubeVideo?, error: Error?) in
if let streamURLs = video?.streamURLs, let streamURL = (streamURLs[XCDYouTubeVideoQualityHTTPLiveStreaming] ?? streamURLs[YouTubeVideoQuality.hd720] ?? streamURLs[YouTubeVideoQuality.medium360] ?? streamURLs[YouTubeVideoQuality.small240]) {
playerViewController?.player = AVPlayer(url: streamURL)
} else {
self.dismiss(animated: true, completion: nil)
}
}
}

关于swift3 - 无法比较 Swift 3 中的 AnyHashable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40563476/

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