Xcode won't recognize a new Swift class

前端 未结 5 1394
时光说笑
时光说笑 2021-01-03 22:40

I have created a new Swift class in a new file

import Foundation

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


        
相关标签:
5条回答
  • 2021-01-03 23:10

    If your class is in another Module, please make sure that your class and the class initializers have the public access modifier.

    0 讨论(0)
  • 2021-01-03 23:14

    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:

    enter image description here

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

    0 讨论(0)
  • 2021-01-03 23:29

    I just had to do the Full Monty to get it to work...

    1. Comment out referencing lines
    2. Fix other bugs to ensure a build
    3. Cmd+Shft+K (Clean build folder)
    4. Nay...let's delete the build folder: /Users/[YOU]/Library/Developer/Xcode/DerivedData/project-name-ADM2KD...
    5. Restart Xcode
    6. Build
    7. Uncomment our referencing lines

    Also maybe add @objc to the line above your class definition and maybe make it public class just to be explicit and possible add public to your methods as well. Oh and make sure you are subclassing NSObject.

    If you are stuck getting your initialiser to show up, I've also just noticed that Swift 4.2 has lots more problems here. I switched back to Swift 3. No problems...

    0 讨论(0)
  • 2021-01-03 23:30

    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).

    0 讨论(0)
  • 2021-01-03 23:33

    For me, I had to check the same target memberships on the class as in the ViewController (I had a TodayExtension)

    0 讨论(0)
提交回复
热议问题