本文介绍了无法分配类型为“字符串"的值键入"UILabel"迅速的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个有关数学测试随机生成器的程序.但是,当我创建一个随机操作时.我使用arc4random_uniform()创建一个随机数.这是功能.

I'm making a program that 's about a math test random generator.But while I was creating a random operation. I used arc4random_uniform() to create a random number. Here's the function.

func generateQuestion() {
        var randomoperation:UInt32 = arc4random_uniform(3)
        if randomoperation == 0 {
            operation = "+"
        }
        if randomoperation == 1 {
            operation = "-"
        }
        if randomoperation == 2 {
            operation = "X"
        }
        if randomoperation == 3 {
            operation = "/"
        }
    }

这将产生错误无法迅速将值类型"String"分配为键入"UILabel""您如何解决这个问题?

This creates the error "Cannot assign a type of value "String" to type "UILabel" in swift"How do you fix this?

推荐答案

func generateQuestion() {
    switch arc4random_uniform(4) {
    case 0:
        operation.text = "+"
    case 1:
        operation.text = "-"
    case 2:
        operation.text = "X"
    case 3:
        operation.text = "/"
    default:
        operation.text = ""
    }
}

这篇关于无法分配类型为“字符串"的值键入"UILabel"迅速的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 02:33