无法调用didSet中的函数。错误消息:“表达式解析为未使用的函数”

时间:2017-03-12 20:34:11

标签: swift function didset

class HomeViewController: UIViewController
{

// The timer is used to check when the download is complete and will only allow segues when it is
var timer = Timer()
var segueName: String = ""
static var didSelectTabBar = false
static var tabBarSegueName = ""

static var startAnimation: Bool = false
{

    didSet
    {
        if startAnimation == true
        {
            updateCounting(<#T##HomeViewController#>)
            loadAnimation(<#T##HomeViewController#>)

        }
    }
}

didSet的变量正在单独的Swift文件中更改并且有效,我可以转到if语句。但我无法使函数工作并为两者收到相同的错误消息。

updateCounting

func updateCounting(){

    if MyVariables.allSoldiersDownloaded
    {
        HomeViewController.startAnimation = false
        loadingImageView.stopAnimating()
        loadingImageView.isHidden = true
        if HomeViewController.didSelectTabBar == false
        {
            self.performSegue(withIdentifier: self.segueName, sender: nil)
        }

        timer.invalidate()
        MyVariables().setGlobalSoldier(id: MyVariables.facebookSoldierID)
        soldierOfHourButton.setTitle("Soldier of the Hour: \(MyVariables.globalSoldier.christian_names) \(MyVariables.globalSoldier.surname)", for: UIControlState.normal)
        soldierOfHourButton.sizeToFit()

    }
    else {
        //print("Not downloaded yet")
    }
}

loadAnimation

func loadAnimation() {
    //creates and stores all the names for the images used in an array
    var imagesNames = ["run1-1.jpg", "run2-1.jpg", "run3-1.jpg", "run4-1.jpg", "run5-1.jpg", "run6-1.jpg", "run7-1.jpg", "run8-1.jpg", "run9-1.jpg", "run10-1.jpg", "run11-1.jpg"]

    //create new uiimage array
    var images = [UIImage]()

    //loop through all the photos in the imagesNames array and add them to the images array
    for i in 0..<imagesNames.count{
        images.append(UIImage(named: imagesNames[i])!)
    }

    //tell testview what images to use for the animation
    loadingImageView.animationImages = images

    //tell testview how long to show a single image for
    loadingImageView.animationDuration = 0.9


    //start the animation in the image view called test view
    loadingImageView.startAnimating()
    loadingImageView.isHidden = false
}

2 个答案:

答案 0 :(得分:0)

替换

        updateCounting(<#T##HomeViewController#>)
        loadAnimation(<#T##HomeViewController#>)

        updateCounting()
        loadAnimation()

答案 1 :(得分:0)

欢迎来到SO。请提供尽可能多的信息(例如完整堆栈跟踪),并正确格式化您的问题(请参阅我的编辑)。通过这种方式,您可以更快地获得帮助。

<#T##HomeViewController#>是什么意思?

应该只是updateCounting() and loadAnimation()

Playground