i have a button, I have inheritance with the state of button. How to get it into an array, and after that - to take the state? Another meaning - how to make an array of not only buttons, but buttons with state, and after that - how to indicate the state after clicking certain CheckerTable.sharedInstance[i][j]. I could have two parallel arrays of buttons and states, but i'd like to haveonly one array.
1. I have an error "Cannot assign value of type '[[(UIButton, CheckEmpty.PlaceState)]]' to type '[[CheckEmpty]]'" and without ".0" in array.
2. How to het the state exactly from CheckerTable.sharedInstance[i][j]
class CheckEmpty: UIButton {
struct PlaceSet {
var background: UIColor?
var image: UIImage?
}
enum PlaceState {
case emp
case inn
case sel
case rea
}
let checkEmptyStyle = PlaceSet(background: UIColor(red: 0, green: 0, blue: 0, alpha: 0.18), image: nil)
var checkerPlace: UIButton!
var checkerState: PlaceState!
...
func place(checkerX: Int, checkerY: Int) -> (UIButton, PlaceState) {
let scale = screenSettings.minimalScaleFactor()
checkerPlace = UIButton(frame: CGRect(origin: CGPoint(x: checkerX*placeDistance*Int(100*scale)/100+Int(screenSettings.scWidth)/2-radius*Int(100*scale)/100, y: checkerY*placeDistance*Int(100*scale)/100+Int(screenSettings.scHeight)/2-radius*Int(100*scale)/100), size: CGSize(width: radius*2*Int(100*scale)/100, height: radius*2*Int(100*scale)/100)))
checkerPlace.backgroundColor = checkEmptyStyle.background
checkerPlace.layer.cornerRadius = CGFloat(radius*Int(100*scale)/100)
checkerPlace.layer.borderColor = UIColor(red: 1, green: 1, blue: 1, alpha: 1).cgColor
checkerPlace.layer.borderWidth = 1
checkerPlace.showsTouchWhenHighlighted = false
checkerState = PlaceState.emp
return (checkerPlace, checkerState)
}
}
And the ViewController below...
struct CheckerTable {
static var sharedInstance = [[UIButton]](). //or should it be [[CheckEmpty]]?
}
class StartViewController: UIViewController {
let screenSettings = ScreenSettings()
let checkIn = CheckIn()
let checkEmpty = CheckEmpty()
var xX = 0
var yY = 0
override func viewDidLoad() {
super.viewDidLoad()
//utworzenie tablicy głównej - startowej - przyciski
CheckerTable.sharedInstance = [[
checkIn.place(checkerX: -1, checkerY: -1).0,
checkIn.place(checkerX: 0, checkerY: -1).0,
checkEmpty.place(checkerX: 1, checkerY: -1).0
],[
checkIn.place(checkerX: -1, checkerY: 0).0,
checkIn.place(checkerX: 0, checkerY: 0).0,
checkIn.place(checkerX: 1, checkerY: 0).0
],[
checkIn.place(checkerX: -1, checkerY: 1).0,
checkIn.place(checkerX: 0, checkerY: 1).0,
checkIn.place(checkerX: 1, checkerY: 1).0
]]
print(xX)
print(yY)
//wstawienie przycisków na ekran - wypełnienie planszy, oznaczenie każdego przycisku tagiem, definicja segue ad target
for j in 0...2 {
for i in 0...2 {
let loopTable = CheckerTable.sharedInstance[i][j]
view.addSubview(loopTable)
loopTable.tag = 10 * i + j
loopTable.translatesAutoresizingMaskIntoConstraints = true //make true otherwise does not display correct
loopTable.addTarget(self, action: #selector(gameUpdate), for: UIControl.Event.touchUpInside)
}
}
Thank You for help!