view swift interface for Objc file - objective-c

I am working in a mixed ObjC Swift project. I am currently overriding functions that where written in ObjC in a swift subclass. I'm wondering if there is a quick way to view the auto generated Swift header files for the objC file so that I can check the syntax of functions after they have been converted to swift.

I'm wondering if there is a quick way to view the auto generated Swift header files for the objC
Switch to the Generated Interface in the first menu of the jump bar.
Example: before:
after:

Related

How to temporarily disable Swift to Objective-C bridging header auto-generation?

Background
Let's say project App is a 50/50 mixed Swift/Objective-C codebase.
Objective-C files import some Swift via auto-generated "App-Swift.h" file.
#import "App-Swift.h"
Recap on How it Works
"App-Swift.h" file automatically includes all the Swift's classes inherited from Objective-C ones: NSObject, UIView, UITableViewCell, UIViewController, etc; and of course all the #objc and #objcMemmbers attributed things.
The Issue
When anything is added to the "App-Swift.h" - all the Objective-C files that import it - have to be recompiled. Even if what was added to Swift is actually not used in any of Objective-C files, but we just inherited from, e.g., UIView.
It all adds up when you import "App-Swift.h" into many files and it slows you down.
Possible Proper Solutions
Break down the codebase into small modules, so interface segregates; avoid NSObject inheritance; Convert as much Objective-C to Swift as possible; private all #IBOutlet, #IBAction during development; etc.
The Question: Cutting a Corner
Is there a way to disable Swift to Objective-C bridging header ("App-Swift.h") auto-generation (but keep the last generated App-Swift.h) at least manually via any of Swift compiler flags?
Any other quick win ideas here?
Related References Revised
Swift and Objective-C interoperability
https://dmtopolog.com/code-optimization-for-swift-and-objective-c/
https://swift.org/blog/bridging-pch/
https://developer.apple.com/documentation/swift/imported_c_and_objective-c_apis/importing_swift_into_objective-c
Going into modules
https://blog.griddynamics.com/modular-architecture-in-ios/
https://www.bignerdranch.com/blog/it-looks-like-you-are-trying-to-use-a-framework/
https://www.bignerdranch.com/blog/it-looks-like-youre-still-trying-to-use-a-framework/

How to see the Objective-C names for Swift functions

Is there a way for me to see the Objective-C translated names for all Swift functions in a file in Xcode?
Objective-C code imports Swift by including an auto-generated
header file which contains the Objective-C interface of all (Objective-C
visible) Swift classes and methods:
#import "<ProductModuleName>-Swift.h"
To view the contents of this file:
Command-click on "<ProductModuleName>-Swift.h" in the Xcode
source file editor,
choose "Jump to Definition".

How do I call Swift code from Objective-C in a Framework target?

When you add a Swift file to an Objective-C project, Xcode will generate a Swift-to-ObjC header, as described here: http://ericasadun.com/2014/08/21/swift-calling-swift-functions-from-objective-c/
Without this header it is not possible to call Swift code from Objc-C. However Xcode is not auto-generating this header for my framework target.
If I create an Objective-C app and drop a Swift file into it, then it does auto-generate one, so I suspect it's because I'm building a framework and not an app. Without one its not possible to use the Swift code from the Obj-C code.
I tried using the one which was generated for the app (after renaming it and putting it in the appropriate DerivedData folder ) but Xcode didn't update it and actually it will eventually delete it, so manually creating or trying to maintain this file is not feasible.
How can I make Xcode generate this header for a framework target, so that I can call my Swift code from my Obj-C code?
And remember folks: the question is about calling Swift from Obj-C not calling Obj-C from Swift.
I created a new Framework project, added both Obj-C and Swift files, and was able to do this:
// MyObjCClass.m
#import "MyObjCClass.h"
#import <MyFramework/MyFramework-Swift.h>
#implementation MyObjCClass
- (void)test {
[[MySwiftClass alloc] init];
}
#end
Note that your Swift class must be public:
public class MySwiftClass: NSObject {
// ...
}
More information is available in Apple's Swift/Obj-C interop documentation under "Importing Swift into Objective-C".

How to hide an Objective C declaration from Swift

I'm working on a library written in Objective-C. I want to have some methods available to callers written in Swift, and not available to callers written in Objective-C.
Going in the other direction, you can control Swift visibility in Objective-C with the #objc and #nonobjc attributes. Are there equivalents to make some Objective-C methods Swift-only or Objective-C-only?
Would I have to maintain a separate header? And if so, is there any way I could require Swift users to import Library-Swift.h in their bridging headers instead of Library.h?
You need separate headers,one for swift and one for objc(for the class).And for swift you could make a header for the whole framework(just for swift,and where you put the swift header for that class),and who wants to use your framework in swift include that header into their bridging header.

Can we use swift with objective-c in same class

I have been reading through Apple documentation and as I read it is possible to use Swift classes in existing Objective-c project.
My question is, Can I use Swift code with objective-c code in the same class, in my existing Objective-c project?
Thanks
If you mean Objective C and Swift in the same file, no, you can't.
What you can do is create a class in Objective C, and add extensions in a Swift file, or the opposite
No, a class must be defined in Swift or in Objective-C not mixed language inside single class file, sorry .
As you may have already noticed a class in swift is generally made by a single file with .swift extension, while objective-C class is defined using two files .h and .m . So, a .h or .m can't contain swift code, the compiler will gives you some errors ...