简体   繁体   中英

Generate Xcode Project from iOS App

Is there a way to create an app that generates an Xcode project that a developer can run in Xcode. Kind of like a code generator. I'm trying to look for answers in the web but to no avail. I'm also not sure where to start. Basically, the app will generate Xcode compatible codes which a developer can use to open to Xcode.

A sample application that's available in the AppStore that offers the same functionality is Interface for iOS. Link: https://itunes.apple.com/en/app/interface/id360543182?mt=8

Another example is Dapp the App Creator: https://itunes.apple.com/au/app/dapp-app-creator-make-learn/id370888555?mt=8

From their app description:

Xcode Export, Turn Your Mockup into Live Codes Our free cloud based Xcode export service will convert your entire project into an Xcode project in just one single tap.

Dapp creates your complete Xcode Project for you - including code, images, videos and Xcode Storyboards!

UPDATE: I was thinking of including a zip file of a sample Xcode project template file inside the app that will generate codes that will be used by the template project, edit or add them in the template project, zip and export to Documents folder thru iTunes File Sharing.

The app whose link you have posted is just used to create mockups. It does not generate code.

It is not possible to make an app that will generate code that you can later somehow import in xcode and run it.

  1. Open Xcode, create a new project, choose Single View Application (or something that best suits what you'll be generating) click create.

  2. Go to the directory where this project was created, zip it and include it in the project for the App that will do the generating.

  3. When it's time to generate the code, step 1 is to create a working directory and unzip the project to it.

  4. Generate your classes etc. and put them into the directory where the AppDelegate.h and the other files generated for you from the Single View Application template are.

  5. Open the xcodeproj package, at the root level there will be a file called project.pbxproj, read it into memory

  6. Modify the project.pbxproj to include the generated code files, there will be a section called PBXFileReference where you can do this.

Here's an example PBXFileReference section from a project I had handy:

    /* Begin PBXFileReference section */
        DB6C03BA1B148F56007554E7 /* UIAlertController.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = UIAlertController.app; sourceTree = BUILT_PRODUCTS_DIR; };
        DB6C03BE1B148F56007554E7 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
        DB6C03BF1B148F56007554E7 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
        DB6C03C11B148F56007554E7 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
        DB6C03C21B148F56007554E7 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
        DB6C03C41B148F56007554E7 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = "<group>"; };
        DB6C03C51B148F56007554E7 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = "<group>"; };
        DB6C03C81B148F56007554E7 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
        DB6C03CA1B148F56007554E7 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = "<group>"; };
        DB6C03CD1B148F56007554E7 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = "<group>"; };
        DB6C03D31B148F56007554E7 /* UIAlertControllerTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = UIAlertControllerTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
        DB6C03D81B148F56007554E7 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
        DB6C03D91B148F56007554E7 /* UIAlertControllerTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = UIAlertControllerTests.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
  1. Write your changes to project.pbxproj (I imagine there may be more than simply the PBXFileReference depending on the complexity of what you're trying to achieve).

  2. Zip the contents of your working directory for the project and email or UIDocumentInteractionController them out to the user.

This is a good article on the pbxproj file: http://danwright.info/blog/2010/10/xcode-pbxproject-files/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM