I have created a new Swift class in a new file
我在一个新文件中创建了一个新的Swift类
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.
但是Xcode给了我一个错误"使用未声明类型RecordedAudio"所以我被困在那里了。这里也有一个类似的问题:如何从另一个Swift文件导入Swift文件?但这些解决方案对我都不起作用。顺便说一句,这是Udacity swift等级的一部分。谢谢,任何帮助都将不胜感激。
3 个解决方案
#1
32
In the Project Navigator on the left, select the file where you declared RecordedAudio.
在左边的Project Navigator中,选择您声明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:
现在,在右边的文件检查器中,查看目标成员。应该检查app目标(不是测试目标),类似如下:
If not, check it! And now all will be well.
如果不是,检查它!现在一切都会好起来。
#2
1
In my case I had to remove the references from the project navigator, and then add them again (the target membership was not the problem).
在我的例子中,我必须从项目导航器中删除引用,然后再添加它们(目标成员关系不是问题所在)。
#3
0
For me, I had to check the same target memberships on the class as in the ViewController (I had a TodayExtension)
对于我来说,我必须检查类上与ViewController中相同的目标成员关系(我今天有一个扩展)
#1
32
In the Project Navigator on the left, select the file where you declared RecordedAudio.
在左边的Project Navigator中,选择您声明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:
现在,在右边的文件检查器中,查看目标成员。应该检查app目标(不是测试目标),类似如下:
If not, check it! And now all will be well.
如果不是,检查它!现在一切都会好起来。
#2
1
In my case I had to remove the references from the project navigator, and then add them again (the target membership was not the problem).
在我的例子中,我必须从项目导航器中删除引用,然后再添加它们(目标成员关系不是问题所在)。
#3
0
For me, I had to check the same target memberships on the class as in the ViewController (I had a TodayExtension)
对于我来说,我必须检查类上与ViewController中相同的目标成员关系(我今天有一个扩展)