This question already has answers here:
How do I call Objective-C code from Swift?
(17 answers)
Closed 4 years ago.
I am working on an application which is built in objective C.
I have to implement UIActivityController which is easy to implement using swift in any application but since I am not familiar with Objective- C even by a %, can I use swift code to implement the UIActivityController in a button?
If so, how?
Yes you can create Swift file, with your Swift implementation in the Objective-C project.
You just have to add
#import "YourProjectName-Swift.h"
into the objc file where you wanna call the swift code and execute it.
More info in article here for example https://medium.com/ios-os-x-development/swift-and-objective-c-interoperability-2add8e6d6887
Related
Is it feasible to code some files in swift and some files in objective c while creating a custom module for IOS in react native. I need this because I know swift but I want to use already created code in objective c, while working on react native project?
Yes you can use both. You need to have a bridging header so that the the Swift code can access the Objective-C code
These tutorials show you how to create native components using swift
https://teabreak.e-spres-oh.com/swift-in-react-native-the-ultimate-guide-part-1-modules-9bb8d054db03
https://teabreak.e-spres-oh.com/swift-in-react-native-the-ultimate-guide-part-2-ui-components-907767123d9e
This tutorial shows you how to use Objective-C code in Swift and vice versa.
https://www.ios-blog.com/tutorials/objective-c/how-to-use-objective-c-classes-in-swift/
My existing iOS app is in objective c language and i want to add more functionality in my app and i want to do that code in swift language.
So is it possible to create an app which contains both the languages(i.e. in objective c & swift) and Is my app will work fine?
In short answer, Yes.
If you have existing project written in objective-c then you can add new classes written in swift. You still have choice if you want to use swift 3.0 ot swift 2.0.
You have to use bridge class in order to achieve that. You will get more guide on Link provided on Apple website.
https://developer.apple.com/library/content/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html
However going forward it would make sense that you spend more time on Learning Swift as Apple is now leaning towards Swift 3.0.
Here is link quick guide.
This question already has an answer here:
What is other option available in swift instead of refactoring and renaming class or attribute name?
(1 answer)
Closed 6 years ago.
I am working on swift project.After 1 month I need to refactor the code as we have done in objective c. I need to change some class names, properties and method names. But problem is that when I go to refactor the code but It showing me an error.
Error is "Xcode can only refactor C and Objective-C code."
Is there any way to refactor the code because there are 50+files to change the code.
Thanks in advance
Unfortunately, no. We're stuck with "Find>Find & Replace in Project".
This question already has answers here:
How to use Namespaces in Swift?
(9 answers)
Closed 5 years ago.
Hy guys,
Do you know how can I create a module(namespace) in swift ? For example in C# we have namespace keyword, but in Objective-C there is no such thing, there we named our classes with the prefix of the folder they were located in. Shall I use the same approach in swift or do you know some other way to achieve namespacing in swift.
Thank you!
You can achieve it by using Frameworks which is newly introduced in iOS 8 for namespace-ing, if I am not mistaken.
I think I will either rename my classes to have a prefix of two capital letters like NSString, UIView and other classes from Objective-C do or I will wrap them in structs.
Thank you for your comments.
This question already has answers here:
How do you enable ARC project-wide in Xcode 4.2
(3 answers)
How to automatically convert Manual Retain-Release code to ARC?
(2 answers)
Closed 9 years ago.
I have an project in nonARC mode. How to change it to ARC mode without create new project?
Is there any auto convert method, library or way?
I also want auto delete release,autorelease and change some text(retain -> strong,...)
This screen shot will help you
Read this DaveOnCode and Migrating your code to Objective-C ARC.