I want to make a truth or dare game in swift playground for iPad but I can't make a button that
prints more than one dare or truth. I tried to make a var that have all dares and then i put it in the
(class Responser NSObject )the var looks like this( var dares = ["dare1", "dare 2" ...]) but it is
giving me error that says (cannot assign value of type '[String]'to type 'String') and the 2nd
thing I tried was (let dares = ["dare 1", "dare 2"…]) that gave me the same error.
my code looks like this
import PlaygroundSupport
import UIKit
let View = UIView()
View.backgroundColor = .blue
let lbl = UILabel(frame: CGRect(x: 210, y: 329, width: 200, height: 50))
lbl.text = "hi!"
View.addSubview(lbl)
lbl.textColor = .white
let button = UIButton(frame: CGRect(x: 67, y: 500, width: 100, height: 50))
button.backgroundColor = .green
//button.setTitleColor(#colorLiteral(red: 0.0, green: 0.0, blue: 0.0, alpha: 1.0), for: UIControlState.selected)
button.setTitle("button", for: UIControl.State.selected)
button.layer.cornerRadius = 10
View.addSubview(button)
let button1 = UIButton(frame: CGRect(x: 300, y: 500, width: 100, height: 50))
button1.backgroundColor = .red
//button1.setTitleColor(#colorLiteral(red: 0.0, green: 0.0, blue: 0.0, alpha: 1.0), for: UIControlState.selected)
button1.setTitle("button1", for: UIControl.State.selected)
button1.layer.cornerRadius = 10
View.addSubview(button1)
class Responser: NSObject
{
//Method to be called
@objc func printname()
{
lbl.text = "1"
}
}
let responder = Responser()
button.addTarget(responder, action: #selector(Responser.printname), for:.touchUpInside)
class Responser1: NSObject
{
//Method to be called
@objc func printname()
{
lbl.text = "2"
}
}
let responder1 = Responser1()
button1.addTarget(responder1, action: #selector(Responser1.printname), for:.touchUpInside)
PlaygroundPage.current.liveView = View
Selecting any option will automatically load the page