簡體   English   中英

在Swift中將數組傳遞給函數拋出無效的參數類型錯誤

[英]Pass an array to a function in Swift throwing invalid parameter type error

這是一個非常基本的問題,但是卻塞滿了我...

我正在嘗試使用此方法調用一個函數(在另一個類中定義):

 var idarray = Profile.getIDArray(Globals.friendlist);

其中Globals.friendlist是一個配置文件數組(即[Profile?])

現在這是我的.getIDArray函數

func getIDArray(inputarray:[Profile?]) -> [String] {
  //Blah - code that returns an array of Strings
}

每當我嘗試編譯它時,我總是收到以下錯誤:

Cannot invoke 'getIDArray' with an argument list of type '([Profile?])'

現在這是我感到困惑的地方-因為我可以肯定我的函數正在接受[Profile?]作為參數類型!

發生了什么問題-我不知道有沒有迅速引入一些內容?

您正在將getIDArray作為類型方法調用。 可能您在func聲明中缺少classstatic關鍵字:

class func getIDArray(...  // if Profile is a class

static func getIDArray(... // if Profile is struct or enum

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM