1

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.

2
  • 3
    Why do you need to do this? Xcode projects change; could be created for Obj-C code initially and added Swift files afterwards. Commented Jun 19, 2018 at 11:12
  • @meaning-matters I am writing a tool which will add a given component(hosted somewhere) to the xcode project. So I want to detect the project dev language and add component according to its dev language. Commented Jun 19, 2018 at 11:21

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! "ObjC project always contains the entry point that is main function." 🔥🔥🔥

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.