How to hide an Objective C declaration from Swift - objective-c

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.

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/

view swift interface for Objc file

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:

Exclude Objective C Category from some Swift classes

In objective C, a Category will only "be used" in a class if I import it. So if I have a Category NSString+category, I have to #import NSString+category.h in each class I want to use it.
I have such a Category, and some of the classes I want to use it in are written in Swift. If I expose this category to Swift by putting it in the Bridging header, ALL swift classes will use it. How can this be avoided?
Note: My Category is actually on UIViewController and the code I have put there must only be used by SOME ViewControllers. It feels wrong and unneccessary to use this Category on the "other" ViewControllers.
Your base assumption is incorrect:
In objective C, a Category will only "be used" in a class if I import it
The methods in a category are present on the class if the category is compiled. Importing the header makes the method names visible; without that the compiler will give you a warning if you try to send a message using one of those names. (You can call the methods using performSelector: or the runtime library if you're determined.)
The same is true of your Swift class, and because of the way Objective-C headers are brought in to Swift, I don't believe there's a way to limit the methods' visibility in your Swift code.

An Objective-C category for an existing Swift class

I would like create an objective-C category for an Swift existing Class:
Creation.swift with its category Creation+Additions.m
I have needed an Obj-C because I have to use a C method. C and Swift together : Oh Dear ! ...
My issue : I have used a dynamic framework in which Objective-C and Swift cohabit. I have got an umbrella header for the bridging Obj-C and Swift.
However, for my category's header Creation+Additions.m, the header AppCreationKit-Swift.swift` is not found.

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