1

Anyone faced problems in {Module_name}-Swift.h file for Swift 4 projects? I've noticed -Swift.h autogenerated file not working well with Swift 4 syntax unlike Swift 3.2!.

For example, -Swift.h file doesn't contain all variables and methods which implemented in the custom Swift classes which inherited from NSObject class!

I've used @objc and @classkeywords but no way.

  • I don't get any errors! the problem is if I've created a class like this:
import Foundation
class Utils: NSObject {
    let abc: String?
    func xyz() { 
        print("")
    }
}

and navigate to {Module_name}-Swift.h I see something like that:

SWIFT_CLASS("_TtC3{Module_name}5Utils") 
@interface Utils : NSObject 
- (nonnull instancetype)init OBJC_DESIGNATED_INITIALIZER; 
@end

Problem

Both let abc: String? and func xyz() have been never included in {Modue_name}-Swift.hfile!

jawad
  • 775
  • 6
  • 16
  • See https://stackoverflow.com/questions/44762460/swift-4-this-class-is-not-key-value-coding-compliant/ and https://stackoverflow.com/questions/44390378/how-can-i-deal-with-objc-inference-deprecation-with-selector-in-swift-4 – Martin R Mar 27 '18 at 12:51
  • @elgawady14 As to why it's not working with your project, can you edit your answer with the error? – Oliver Atkinson Mar 27 '18 at 21:13
  • @OliverAtkinson thanks for the reply, checkout my last update. – jawad Mar 28 '18 at 11:09

4 Answers4

0

I think in Swift 4 you have to mark a lot more things @objc (nothing implicit anymore) but other than that it should just be in there.

Alper
  • 3,424
  • 4
  • 39
  • 45
0

You can all check it to confirm class name in .h file like:

@class filename;

Jogendar Choudhary
  • 3,476
  • 1
  • 12
  • 26
0

The generated file {Module}-Swift.h does not contain your variables and methods, the file is generated to give you access to the Module namespace.

The actual interface for the generated module lives in Module.swiftmodule/arm64.swiftmodule (depending on built architecture).

More information on its contents:

however... the format is not documented anywhere and is subject to change. A good starting point would be to look in include/swift/Serialization/ModuleFormat.h


As to why it's not working - Swift 4 has a migration process, please ensure you have followed it: https://swift.org/migration-guide-swift4/

Xcode will pick up most things ... but it won't get everything!

Oliver Atkinson
  • 7,970
  • 32
  • 43
  • I've mentioned the problem specifically for the case I've faced in my last update. – jawad Mar 28 '18 at 11:18
  • @elgawady14 And how are you getting access to the `-Swift.h` file? Typically the generated one won't have any header information like the one you are posting - I'm happy to take a look if you can produce it in a simple sample project – Oliver Atkinson Mar 28 '18 at 15:58
  • sry for late reply! you can access `-Swift.h` file after you build your code by highlighting `{your_module}-Swift.h` and right click then go to 'Jump to Definition', the file content will shown up immediately! – jawad Dec 20 '18 at 09:32
-1

And why do you need header files for Swift classes? You just can mark swift class as @objc and you will be able to reach all its properties.

Bio-Matic
  • 793
  • 1
  • 8
  • 20
  • It does, because it would fix his problem. Mark swift class with @objc and you won't even need header files. – Bio-Matic Mar 27 '18 at 14:31