我刚接近斯威夫特,我遇到了一些问题......
我有一个课程可以帮助我获取一些结果
class ExpencesOperations {
struct ExpencesByDate {
var day: String!
var expence: [PFObject]
}
var expencesByDateArray = [ExpencesByDate]()
func getExpencesByDate(expences: [PFObject]) -> [ExpencesByDate] {
..... my function
return expencesByDateArray
}
}
当我在TableViewController中调用它时,我不知道如何重新声明struct ExpencesDate!
class HomeTableViewController: UITableViewController {
var myCurrency = MyCurrency()
var expencesOperations = ExpencesOperations()
var expencesByDateArray = [ExpencesOperations.ExpencesByDate]() /* Not Working */
func fetchExpences() {
expencesByDateArray = self.expencesOperations.getExpencesByDate(someInput) /* here i get the error */
}
答案 0 :(得分:4)
将结构放在类范围之外,它也应该对其他文件可见。
struct ExpencesByDate {
var day: String!
var expence: [PFObject]
}
class ExpencesOperations {
var expencesByDateArray = [ExpencesByDate]()
func getExpencesByDate(expences: [PFObject]) -> [ExpencesByDate] {
..... my function
return expencesByDateArray
}
}
答案 1 :(得分:0)
你需要提供正确初始化ExpencesByDate结构的参数(我认为你的意思是Expen S es,对吗?)
例如:
var expencesByDateArray = [ExpencesOperations.ExpencesByDate(day: "Friday", expence: [PFObject]())]
关于:
... getExpencesByDate(someInput)/ *这里我得到错误* /
您创建的函数需要一个数组:
func getExpencesByDate(expences: [PFObject]) -> [ExpencesByDate]
从您的问题中不清楚someInput
是什么。那是一个阵列吗?
正如你在问题中发表的那样,它总会失败。
另外,编译器错误消息是什么?