Can we build and upload ios app with swift and objective-c mixed code? - ios

Actually, I am working on one app and started with the objective-c. Now i have started working on swift with the same app for the further development and it will work with both the class (objc and swift).
Now I have doubt that it will accept by apple store or not.
Please help me.

This is fine, Apple provides the mechanisms for interacting with both and will not drop support for Objective-C for quite sometime. Many large organisations still have the majority of their code written in Obj-C (including Apple) so they need to give people time to transition, they aren't going to switch over immediately to a relatively immature language.

You can use Swift and Objective-c together. There is no issue in it. You need to create a bridging header file.
Please read this
Swift and Objective-C in the Same Project

Related

Is it possible to write iPhone app in both objective c and 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.

Can swift code be used in Codename One native code instead of Objective-C

I need to insert native code in my Codename One app. I am a completely newbie in iOS programming so I need to learn Objective-C. However I read that Swift was the successor of Objective-C and I would feel more comfortable with Swift syntax. But I don't know if Swift is supported in Codename One. While looking at iOS source code generated by Codename One, although I am not 100% sure, it looks like C code (I may be wrong).
On his blog Shannah (from Codename One) wrote that
Codename One currently compiles everything down to plain old C code so we would be largely unaffected by such a change – although there would be some native portions that use Objective-C that would need updating. Luckily, if you’re a Codename One user, you don’t need to concern yourself with these details because you are working in Java.
I don't get it clear that's why I am asking whether it is possible to use Swift code in Codename One native code ?
Thanks a lot for helping me clarifying this topic!
Cheers
Yes and no. You can probably compile Swift code to a static library today (.a file) and just use that like any static lib where the Objective-C code just acts as a bridge.
Using Swift directly is problematic due to several factors:
Currently we are still using an older version of xcode when building, we made an attempt at migrating to the latest but had a setback. We'll migrate hopefully before 3.5 comes out, if not then shortly after.
Swift requires a relatively new version of xcode so until we do that embedding Swift code will be problematic.
Swift assumes ARC. This is something we tried to integrate with the GC but at this time it doesn't really work well.
We need to generate Swift stubs as an option, this is problematic as say you have existing cn1lib or native interface that relies on Objective-C it might create a conflict.
But lets back track a bit. Swift is a huge advantage over Objective-C which is pretty old by now. But it doesn't have any major advantages for Codename One developers...
It isn't faster as Codename One translates to C which is faster than both Swift and Objective-C
It won't make the code much cleaner, if you have a lot of code in your native interfaces then you are doing something wrong. Most of your code is in Java anyway, you can debate the merits of Java vs. Swift but if you are using Codename One then you pretty much picked Java.
If you need to use an app written in Swift you can package it as a static library.
So there is really no real use case for Swift in Codename One at this time.

iOS 9, Swift 2.0 , Xcode and testing

I am planning to learn to develop iOS apps. I'll most probably be learning Objective-C only for now and would like to develop some actual apps for iOS.
Now, with the launch of Swift 2.0, will Objective-C apps still run on iOS9 ? Also, is it possible to test run an Objective-C app on your phone like mentioned here ? https://developer.apple.com/xcode/
Or is this facility available only for apps written in Swift?
Does Swift allow me to do everything that Objective-C does?
Any further advide or guidance for what should I know before enrolling for the course will be appreciated to help me judge things better.
Swift is still just the second language. All Cocoa frameworks are written in C or Obj-C (maybe the new ones in iOS 9 are written in Swift).
The language in which an application is written doesn't matter, the code is compiled into the same machine code, so yes, Obj-C apps will continue to run and many developers won't bother with Swift. Apps that have been already written will not have to be rewritten to Swift (with some exceptions).
Swift won't allow you to do absolutely everything that Obj-C does but it will allow you to do almost everything and the code will be probably more robust, considering that Swift is more modern language with stronger typing than Obj-C. If you are a beginner, you won't probably find any problematic use case.

Can we create iOS app with swift and obj c both?

Can we create iOS app with swift and obj c both.My half app is made using OBJ-C and just want to improve apps performance so is that possible to use swift in between
Yes you can.
You have to add objc header #imports in the <module name>-Bridging-Header.h that you want to make available in swift, and you can use swift code from objc by importing the <module name>-Swift.h file in your objc code.
Note that the latter header file is automatically generated when building, and it is not visible in the project navigator - but you can open it by cmd+click-ing its name in an existing #import. Also to note that if compilation fails, most likely the file will not be generated.
Last, I highly recommend that you avoid circular references between objc and swift - for instance, creating a SwiftClass, inherited from BaseObjcClass, and using SwiftClass from objc - I've experienced that it doesn't work (compilation errors), and I am not aware of any workaround
Yes, you can. You just need to follow this:
https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html
Apple’s intention to replace the Objective-C language using Swift, it is not practical in the short term simply due to the fact that developers are deeply entrenched in Objective-C. Rather than force Swift down the developer’s throat, Apple has made it easy to allow Objective-C to interoperate with Swift.
http://mobiforge.com/design-development/using-objective-c-and-swift-together-ios-apps
Dec 2018 - I found this useful YouTube video that helps explain what files you need to add and how to make the connections.
YouTube - How to use Swift and Objective-C in the same project

How to implement AVCam for Swift

Hello I have found two links about AVCam
Apple: https://developer.apple.com/library/ios/samplecode/AVCam/History/History.html
alex-chan/AVCamSwift: https://github.com/alex-chan/AVCamSwift
The first link has demo files that work perfectly, but its in Object-C - can someone show me documentation on converting Object-C to Swift?
The second link I have downloaded the files but it will not run in my 4s - can someone tell me why?
I would like to have a swift version so I can easily adopt it into my swift build + thanks again SO!
if you have a working objc version why not just import it with a bridging header? there is no one document about converting obj-c to swift, if you really want to convert it you are going to need to do it line by line.
also what exactly are you trying to do? get a live camera feed displayed? these docs have been ported to swift and would suit that purpose but you would need to get the input port first.
https://developer.apple.com/library/mac/documentation/AVFoundation/Reference/AVCaptureVideoPreviewLayer_Class/index.html#//apple_ref/occ/clm/AVCaptureVideoPreviewLayer/layerWithSession:
Update: how to import obj-c headers, a newer way to create them that isnt quite as talked about yet is to just create any normal .m file or objective c file then select yes to creating a briding header, it configures everything for you.
That being said it may be worth while to play around with the basics a bit more and maybe follow a few guides before attempting to implement this type of feature if you are having issues with following the links.
Here is a random application creation guide http://www.ioscreator.com/tutorials/calculator-tutorial-in-ios8-with-swift that should teach you alot. i would recommend following and reading through stuff like this until you have a bit more of a footing and can come up with more of an exact question. no one here is going to rewrite the apple program for you and your questions are extremely broad.

Resources