Stuck in a "Expected '}' after if condition" loop, what is the problem? (Started programming yesterday)

import UIKit

import AVKit
import AVFoundation

class ViewController: UIViewController {

override func viewDidAppear(_ animated: Bool) {

@IBOutlet weak var PowerLVLlabel: UILabel!

override func viewDidLoad() {
    // Do any additional setup after loading the view.

@IBAction func randomNumber(_ sender: Any) {
    let randomNumber = Int.random(in: 1000...10000)
    PowerLVLlabel.text = String(randomNumber)
    if case { randomNumber; >=9000 == (true);
         func playVideo() {
            guard let path = Bundle.main.path(forResource: "over 9000", ofType:"mp4") else {
                debugPrint("over 9000.mp4 not found")
            let player = AVPlayer(url: URL(fileURLWithPath: path))
            let playerController = AVPlayerViewController()
            playerController.player = player
            present(playerController, animated: true) {


This is a "using swift" question. Nevertheless and as the error suggests, the code is missing a closing } is a few places.

If a compiler error message is emitted in an endless loop, then that's a bug in compiler. (Parsing incorrect code is much harder than parsing correct code, especially when scoping tokens aren't paired correctly.)


First, welcome to the forums.

Second, please surround code excerpts with triple-backticks (```) to get proper formatting here.

Third, the line:

if case { randomNumber; >=9000 == (true);

should probably be much more simply:

if randomNumber > 9000 {

Fourth, you have a number of unmatched opening braces that need a closing brace at the end of their blocks.

Terms of Service

Privacy Policy

Cookie Policy