'commonModes' has been renamed to 'RunLoop.Mode.common'

How To Build a Match Game - Lesson 10 (Win Condition) using Xcode Version 11.4 (11E146)

added “RunLoop.main.add(timer!, forMode: .commonModes)” and got “‘commonModes’ has been renamed to ‘RunLoop.Mode.common’”, hit Fix and got “Cannot infer contextual base in reference to member ‘RunLoop’”. Can any one advise what I do next? Thanks

Hi @JulianWyllie Welcome to the community!

Is this what you have that is not working?

timer = Timer.scheduledTimer(timeInterval: 0.01, target: self, selector: #selector(timerElasped), userInfo: nil, repeats: true)
        RunLoop.main.add(timer!, forMode: RunLoop.Mode.common)

Let us know and we will have a go.
Blessings,
—Mark

Hi Mark, yep, that’s the fella!

Thanks for getting in touch,

Julian

HI Julian,

if you the code I posted above is not working for your project, post your code and we will take a look.

Thanks.
Blessings,
—Mark

Hi Mark,

Not sure how much of the code you need, let me know -

import UIKit

class ViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource {

@IBOutlet weak var timerLabel: UILabel!

@IBOutlet weak var collectionView: UICollectionView!

var model = CardModel()
var cardArray = [Card]()

var firstFlippedCard:IndexPath?

var timer: Timer?
var milliSeconds:Float = 10 * 1000 // ten seconds

override func viewDidLoad() {
    super.viewDidLoad()
    
    collectionView.delegate = self
    collectionView.dataSource = self
    
    // Call the getCards method of card model
    cardArray = model.getCards()
    
    // Create timer
    timer = Timer.scheduledTimer(timeInterval: 0.001, target: self, selector: #selector(timerElapsed), userInfo: nil, repeats: true)
    RunLoop.main.add(timer!, forMode: .RunLoop.Mode.common)
}

Thanks,
Julian

Hi Julian,

Remove the first . from the RunLoop.Mode.common and see if that clears your error.

Blessings,
—Mark
.

Hi Mark,

Yes, that certainly does the job!

Thank you very much for that, any idea why the ‘Fix’ put the ‘.’ there?

Julian

You could have used the shorthand method

RunLoop.main.add(timer!, forMode: .common)

forMode: is expecting a Runloop.Mode and whilst it is quite OK to have Runloop.Mode.common it’s more usual to shorthand it with .common.

Thanks for that Chris, I am still on the steep upward learning curve so hopefully I won’t have to ask too many questions like this soon.

Julian

1 Like

Remember there is no such thing as a silly question. We are all here to learn and share what we know in the hope that it helps someone else.