Xcode无法识别新的Swift类 [英] Xcode won't recognize a new Swift class

查看:157
本文介绍了Xcode无法识别新的Swift类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在新文件中创建了一个新的Swift类

  import Foundation 

class RecordedAudio :NSObject {
var filePathUrl:NSURL!
var title:String!
}

现在我想通过创建一个新对象在另一个类中使用它。

  import UIKit 
import AVFoundation

class recordSoundsViewController:UIViewController,AVAudioRecorderDelegate {
var audioRecorder:AVAudioRecorder!
var recordedAudio:RecordedAudio! //新对象给出错误

但是Xcode给我的错误是使用未声明的类型RecordedAudio所以我卡在那儿。此处发布了类似的问题:如何做我从另一个Swift文件导入一个Swift文件?
但这些解决方案都不适用于我。顺便说一句,这是Udacity swift课程的一部分。谢谢,任何帮助将不胜感激。

解决方案

在左侧的Project Navigator中,选择您声明RecordedAudio的文件。 / p>

现在,在右侧的文件检查器中,查看目标成员资格。应用目标(不是测试目标)应检查,类似于:





如果没有,请检查它!现在一切都会好的。


I have created a new Swift class in a new file

import Foundation

class RecordedAudio: NSObject{
    var filePathUrl: NSURL!
    var title: String!
}

and now I want use it inside another class by creating a new object.

import UIKit
import AVFoundation

class recordSoundsViewController: UIViewController, AVAudioRecorderDelegate {
    var audioRecorder: AVAudioRecorder!
    var recordedAudio: RecordedAudio! // new object gives error

But Xcode is giving me the error "Use of undeclared type RecordedAudio" so I got stuck there. A similar question has been posted here: How do I import a Swift file from another Swift file? but none of those solutions worked for me. BTW, this is part of the Udacity swift class. Thanks, any help would be appreciated.

解决方案

In the Project Navigator on the left, select the file where you declared RecordedAudio.

Now, in the File inspector on the right, look at the Target Membership. The app target (not the Test target) should be checked, similar to this:

If not, check it! And now all will be well.

这篇关于Xcode无法识别新的Swift类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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