Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Expected ';' after top level declarator" under Swift

I'm trying to set all my colours in one Swift file that can be used throughout my application.

The following code below results in...

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 top level declarator

like image 612
Damian Worsdell Avatar asked Jul 07 '14 11:07

Damian Worsdell


1 Answers

The same error occurred to me after I've added the first swift file to my objc project. That's how I fixed it:

  1. Make sure you use an "iOS Source" file (not "OS X Source") when you've added the file.
  2. Don't import the swift file in your objc file like: #import "ExampleFile.swift" but use #import "ProjectName-Swift.h"
  3. Make sure you use @objc statements in your swift code that you want to import to objc

These are the links that were helpful:

  • apple documentation
  • how-to-import-swift-code-to-objective-c
like image 148
lukas_o Avatar answered Oct 28 '22 16:10

lukas_o