"预期的 ';'在顶级声明符之后"在 Swift 下 [英] "Expected ';' after top level declarator" under Swift

查看:97
本文介绍了"预期的 ';'在顶级声明符之后"在 Swift 下的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在一个可在整个应用程序中使用的 Swift 文件中设置所有颜色.

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

下面的代码导致...

import Foundation
import UIKit

class DotColors {

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

}

... 预期的';'在顶级声明符之后

推荐答案

在将 第一个 swift 文件添加到我的 objc 项目后,我遇到了同样的错误.这就是我修复它的方式:

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. 确保在添加文件时使用iOS 源"文件(而不是OS X 源").
  2. 不要在 objc 文件中导入 swift 文件,例如:#import "ExampleFile.swift" 而是使用 #import "ProjectName-Swift.h"立>
  3. 确保在要导入 objc 的 swift 代码中使用 @objc 语句
  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:

这篇关于&quot;预期的 ';'在顶级声明符之后"在 Swift 下的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆