Please, when you post code, edit it properly with the formatter tool ().
And provide enough code to let other understand what's going on. And don't hide the problem as a comment in code.
import UIKit
import Foundation
enum gameType {
case easy
case medium
case hard
case player2
}
class MenuVc : UIViewController {
@IBAction func Player2( sender: Any) {
moveToGame(game: .player2)
}
@IBAction func Easy( sender: Any) {
moveToGame(game: .easy)
}
@IBAction func Medium( sender: Any) {
moveToGame(game: .medium)
}
@IBAction func Hard( sender: Any) {
moveToGame(game: .hard)
}
func moveToGame(game : gameType ) {
let gameVc = self.storyboard?.instantiateViewController(withIdentifier: "gameVc") as! GameViewController
currentGameType = game // error here Cannot assign value of type 'gameType' to type 'gameType.Type'.
self.navigationController?.pushViewController(gameVc, animated: true)
}
}
Some comments: enum should start with Uppercase: enum GameType
func and var names would start with lowercase
if you know the type of argument (as UIButton), use it instead of Any
take care to use the exact signature (including underscore)
@IBAction func easy(_ sender: UIButton) {
can anyone explain what wrong in the code
currentGameType = game // error here Cannot assign value of type 'gameType' to type 'gameType.Type'.
How did you define currentGameType ?
I do not see it declared anywhere in code.
It should be gameType
If you have defined
var currentGameType = gameType.self (why ?)
then you get the error message.
But using a code written with Xcode 3 in Xcode 10 will lead to a lot of such problem. Don't try it you will loose your time.
If that answers your problem, please don't forget to close the thread on the correct answer. Otherwise, please explain and provide required code.