"Expected"; after the top-level declarator "under Swift

I am trying to set all my colors in a single Swift file that can be used throughout the application.

The following code below leads to ...

import Foundation
import UIKit

class DotColors {

let tsblueColor = UIColor(red:58/255.0, green: 125/255.0, blue: 208/255.0, alpha: 1.0)

}

... Expected ';' after the top level announcement

+4
source share
4 answers

You forgot to import UIKit.

import UIKit

You can try this,

import Foundation
import UIKit

class DotColors {

  let tsblueColor = UIColor(red:58/255.0, green: 125/255.0, blue: 208/255.0, alpha: 1.0)

}
+2
source

The same thing happened to me after I added a quick first file to my objc project. Here is how I fixed it:

  • When adding a file, make sure that you are using the iOS Source file (not the OS X Source).
  • objc, : #import "ExampleFile.swift", #import "ProjectName-Swift.h"
  • , @objc , objc

, :

+2

import UIKit

. , !

0

, , , OS X Source Cocoa Class iOS Cocoa Touch Class.

, , , iOS.

0

Source: https://habr.com/ru/post/1547394/


All Articles