Reputation: 1328
We can create a new Xcode project using Objective-C or Swift.
I want to detect, which language was selected when a project was created?
Projects can be a mix of Objective-C and Swift, but I am concerned about the language, selected during project creation.
May be it can be through pbxproj file or other better way.
Thanks.
Upvotes: 1
Views: 955
Reputation: 598
ObjC project always contains the entry point that is main function. Usually it is inside main.m file but it is not necessary. Developer can replace it to any name. I tried 2 simple projects. One is in ObjC and second one is in Swift. When I was tried to add new file the Xcode offered Swift language for Swift project and Obj-C for Obj-C project file. Next I removed in Swift project AppDelegate.swift file and added AppDelegate.h and AppDelegate.m and (sic!) main.m files. of course I had to create bridging file for obj-c. Which contains
#import "AppDelegate.h"
I was able to compile this project but when I tried to add new file Xcode offered me to add Objective-C file. But initially the project was created as Swift project.
I did similar manipulation for Obj-C project. I removed AppDelegate.h and .m file as well as main.m and added AppDelegate.swift I was asked to create bridge file and did empty file. Next I went to «Build Settings» and switched Define Module parameter to YES value. (Without this I got linker error).
After it I was able to build and run this initially obj-c project which has AppDelegate in Swift now. When I tried to add a new file the Xcode offered me to add new Obj-C file too. So. It looks like you cannot detect initial language based on a parameter in Xcode because project can be always corrected. I think that rarely the developer will try to replace AppDelegate in a project and add\remove main entry point. Hope this helps you.
Upvotes: 3