调用中的额外参数 userinfo [英] extra argument userinfo in call
问题描述
使用 Swift 语言从 xCode 获取编译错误消息:调用中的额外参数 userinfo".问题是如何将来自计时器的 userInfo 数据用于通知中心的参数userInfo".
Get the compile error message from xCode with Swift language: "extra argument userinfo in call". the question is how to use userInfo data from timer to argument "userInfo" in notification center.
func onSetAudioWithTrackIndex(CurrentTrackIndex:Int, urlAudio: String){
........
//try to pass currentTrackIndex data to timerfire
playTimeClock = NSTimer.scheduledTimerWithTimeInterval(0.4, target: self, selector: "onSetPlayProgressTime:", userInfo: CurrentTrackIndex, repeats: true)
}
//Timerfire
func onSetPlayProgressTime(timer: NSTimer){
var currentTime = mediaPlayer.currentPlaybackTime
var playDuration = mediaPlayer.duration
var trackIndexDict = ["trackIndex" : timer.userInfo]
................
if currentTime == playDuration{
NSNotificationCenter.defaultCenter().postNotificationName(MPMoviePlayerPlaybackDidFinishNotification, object: self, userInfo: trackIndexDict)
}
return
}
推荐答案
Swift 有时会给你带来一些奇怪的编译器错误,这相当于有多种可能的选择,但没有一个有效,所以这里是其中一个的问题".当它抱怨的不是你想要的那个时,这可能很奇怪
Swift can give you slightly strange compiler errors sometimes, which amount to "there were multiple possible options, none of them worked, so here’s what’s wrong with one of them". When the one it complains about is not the one you were trying for, this can be very strange
这就是为什么 Swift 经常告诉你某些东西不是 Int8",即使这与你试图做的事情无关(嗯,我试图连接两个字符串,Int8s 必须做什么有什么? - 这是因为 +
运算符的可能选项之一是在 Int8s 上工作,因此它选择抱怨的那个).
This is why Swift tells you so often that something is "not a Int8" even though that has nothing to do with what you were trying to do (huh, I was trying to concatenate two strings, what have Int8s got to do with anything? – it’s because one of the possible options for the +
operator is to work on Int8s so that’s the one it chooses to complain about).
在这种情况下,postNotificationName
有多个重载版本,一个有 1 个参数,一个有 2 个,另一个有 3 个(你想要的那个).它们都不适合您提供的类型,因此它说其中一个选项是带有 2 个参数的调用,而您提供了 3 个,因此这不起作用,还有一个额外的参数".
In this case, postNotificationName
has multiple overloaded versions, one with 1 argument, one with 2, and one with 3 (the one you want). None of them fit the types you’ve supplied so it’s saying "one of the options is a call with 2 arguments, and you supplied 3, so that won’t work, there’s an extra argument".
不幸的是,这真的很令人困惑,并且让您感觉不到真正错误的地方.假设您剪切并粘贴了实际代码,看起来 MPMoviePlayerPlaybackDidFinishNotification
中存在拼写错误,并且 userInfo
参数标签后面缺少一个冒号.
Unfortunately this is really quite confusing and throws you off the scent of what is actually wrong. Assuming you cut and pasted your actual code, looks like there’s a spelling error in MPMoviePlayerPlaybackDidFinishNotification
, and the userInfo
argument label is missing a colon after it.
(p.s. 你不需要在返回 void 的函数的末尾显式地放置一个 return,尽管它没有任何危害)
(p.s. you don’t need to explicitly put a return at the end of functions that return void, though it doesn’t do any harm)
这篇关于调用中的额外参数 userinfo的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!