在NSObject的返回类型中显示错误

时间:2017-07-10 11:10:54

标签: ios swift

我制作了NSObject来解析collectionView的值。它将构建失败,因为它在重新键入时显示错误。我认为我有编写代码的问题。但我不知道我的错误在哪里,请尽力帮助我。

import UIKit

import Foundation

class AppCategory: NSObject {

    var tShirtImageOb: String?
    var tShirtLabelOb: String?
    var tShirtPrizeOb: NSNumber?


    static func sampleAppCategories() -> [AppCategory] {

        var bestNewAppsCategoryArray = [AppCategory]()

        let bestNewAppsCategory = AppCategory()
        bestNewAppsCategory.tShirtImageOb = "tShirt"
        bestNewAppsCategory.tShirtLabelOb = "Best New Apps"
        bestNewAppsCategory.tShirtPrizeOb = NSNumber(value: 599.0 as Float)
        bestNewAppsCategoryArray.append(bestNewAppsCategory)



        var bestNewGamesCategoryArray = [AppCategory]()

        let bestNewGamesCategory = AppCategory()
        bestNewGamesCategory.tShirtImageOb = "tShirt"
        bestNewGamesCategory.tShirtLabelOb = "Best New Apps"
        bestNewGamesCategory.tShirtPrizeOb = NSNumber(value: 599.0 as Float)
        bestNewGamesCategoryArray.append(bestNewGamesCategory)


        // show the error in down line
        return [bestNewAppsCategoryArray, bestNewGamesCategoryArray]


    }
}

1 个答案:

答案 0 :(得分:1)

如果您想要返回包含所有新游戏和新应用类别的AppCategory对象数组,请将它们一起添加到返回行中。

所以改变这一行

return [bestNewAppsCategoryArray, bestNewGamesCategoryArray]

return bestNewAppsCategoryArray + bestNewGamesCategoryArray