Creating Xcode Project Templates in Xcode 8.2.1 - makefile

How does one go about creating a project template in Xcode 8.2.1? I'm asking this because of how I would like to use such a project template as the basis for the many Xcode projects that I will most likely create in the process of learning how to program in C++ from Bjarne Stroustrup's Programming: Principles and Practices Using C++, Second Edition. Mr. Stroustrup provides his readers with several header files, which I have copied into a GitHub repository, on the book's rudimentary web site, and I would like to figure out how to link them into Xcode's build system.
Someone created a makefile for use with the Darwin base of OS X, but I'd rather be able to use Xcode so that I can learn how to do so while I am learning C++ so that I know how to use it for later projects. I don't know whether I should use this makefile or not, but Apple does provide instructions on 'Building Makefile Projects with Xcode', so should I use those? I've also noticed that other people have similarly asked questions about how to create project templates for older versions of Xcode here, here, here, and here. Would any of the material from these Stack Overflow posts help my prospective answerer or answerers by providing them with some source material for their research?

There seems to be an amazing lack of information on this topic. As far as I know templates have not changed materially since Xcode 4. Templates I made for it still work on Xcode 6.
Like one of the commenters above, I used this post to get started.
I am only developing for macOS (OS X), not iOS.
I also made some file templates, which are much easier; maybe try making one or two of them first. Macro names in file templates do need triple underscores at each end.

In XCode 7.3.1 (and maybe above versions too), you just need to go to Application folder, find XCode and right click on it and pick "Show Package Contents". Then, make your way to:
Contents/Developer/Library/XCode/Templates/..
In here you will find more folders which you mess with. Basically they are the items that appear when you goto XCode->File->New File... Becareful though, cause this is part of the XCode application. Not sure what will happen if you edit or add files wrongly.
ps. You also should quit XCode before opening the package contents.
Hope that helps.

http://robnapier.net/project-templates
This link helps me much,since the macros did not change.
I want to custom a project template. But no automatic tools could be found,I make one my self.
first,drag a template to my desktop from Path below.
Xcode ▸ Contents ▸ Developer ▸ Platforms ▸ iPhoneOS.platform ▸ Developer ▸ Library ▸ Xcode ▸ Templates ▸ Project Templates
( I use the empty template from the link:
https://github.com/tobymao/EmptyApplication.xctemplate)
then,add your files to the *.xctemplate directory .
And edit plist file.
two items needs: Definitions which type should be Dictionary;Nodes which type is Array;
In Definitions for each added file define a correspond Dictionary (name should be filename or filename had PROJECTNAMEASINDENTIFIER as prefix) ,which has key "Path" hold your files' path;
In Nodes ,add all the items defined in Definitions.
and,
if you had your filename has projectname as prefix ,you should change content of your class files,change the classnames to macro FILEBASENAMEASIDENTIFIER
at last ,
move your template directory back, and don't forget to change the identifier in plist.

Related

React Native - multiple targets

I'm creating a RN app that is meant to be some kind of wrapper. It should have multiple targets (like in Xcode) and all its content (images, text, etc.) should be target dependent. Unfortunately, I cannot find any useful informations about how to achieve this without opening Xcode or Android Studio project and create those targets manually (like here). Is there any other solutions for this?
I was still struggling with described problem but I finally found a solution. It's not easy, needs writing a bit of boilerplate code and looks more like a workaround but I hope it will help someone in the future. What I did is I have completed my wrapper app with the resources for one of my targets so I can have visual effect. In the project's root directory I've created a folder with subfolders for each target. Inside each I have put files (images, source code files, other assets) that are target-dependent. Then I've created bash script that takes one argument - target's name. Based on it, it replaces all the target-dependent files from target's subfolder to the original file's destination in the project structure. In this proces all meta-data informations are also replaced so after firing .sh file I can build the app and upload it to both stores. It's really time consuming to create all these apps separately and publish them and it's maybe not the best solution, but at least it works!
On android, you can edit build.gradle files, java or properties, without having to launch Android Studio (which simply uses Gradle)
You can build different type flavours by only changing app/build.gradle
On iOS, that's another story. Project file (.pbxproj) is a mess,and other Workspace/Scheme files are not easy to read or script. So XCode is the way to Go.
I tried to have dynamic target & Info.plist, there are tools to script that like PlistBuddy
in the end, I saw there are many ways to launch a React Native app for developpers. Some prefer the command line, and only VSCode.
Others want to play with native IDE.
By the way, native IDEs are VERY useful.
e.g. : you want to fine-tune your application performance, using XCode view hierarchy debugger or android Studio Layout Inspector (and be sure you don't use to many views), or use any other performance tools these IDEs offer...
In the end, I used react-native-config along with multiple almost similar configs (Info.plist < target < Scheme for each), here's a post giving an overview of the setup.

Xcode workspace reference project by environment variable

I need to reference a project in a Xcode workspace by an environment variable. An Xcode workspace file might look like this:
<Workspace
version = "1.0">
<FileRef
location = "group:../../Some/Dir/SomeLibrary.xcodeproj">
</FileRef>
<FileRef
location = "group:SomeApp/SomeApp.xcodeproj">
</FileRef>
</Workspace>
I want the SomeLibrary project to be referenced by an environment variable, so that the workspace file and projects can be used in different developer environments (the lib project is shared between several different projects). Any ideas on how to do this? Is the XML-format documented somewhere?
Thanks! :)
In your XCode 4 Preferences, you'll see a "Locations" tab and in the "Source Trees" section you can put an environment-variable like location (which you can change from machine to machine). And you can use these settings to change paths for the libraries you're trying to include or reference in your projects.
It's not exactly the environment variable from the Terminal command line, but then again most people don't launch XCode from the Terminal and so you shouldn't expect to pick up your $PATH or other UNIX-style environment variables from double clicking on any app, much less the XCode IDE. It's a good alternative.
There's some more information in this related question and here's Apple's documentation on what they are and how to set them up (which is aimed at XCode 3 but the same concepts apply for XCode 4).
Let me know if I can provide more information, and I hope my answer helps!
I think I need to answer this myself. Based on my research it is not possible to use a dynamic location (environment variable, source tree, etc) on workspace projects.
Solution 1:
You CAN achieve what I'm trying to do using symlinks. In my current workspace I've created one application-project, and a project entry which points to a symlink on the local file system. This way one can switch projects and have dynamic locations for the library-projects. I'm not sure if XCode treated this link properly when adding, so I manually added the project entry like this:
<FileRef
location = "group:Libraries/SomeLibrary/SomeLibrary.xcodeproj">
</FileRef>
Where SomeLibrary (IMPORTANT: The folder SomeLibrary need to be the symlink, or else XCode wont be able to find the project contents) is a symlink to my static library project somewhere else on the local file system. This way, developers can have different paths to the library, and one can easily switch versions when needed.
Solution 2:
Adding a static library project as a subproject and using cross-reference. For sub-projects, one can use Source Tree and use dynamic locations.
I haven't tested these solutions widely, so I'll come back with a reply after using it for a while.

Using AppleScript to Add Files, Frameworks and Libs to XCode 4

I'm doing a Unity-iPhone project, but want to automatically add some native code and relative frameworks and libraries to the XCode 4 project when I get it from Unity. What I know is the basic usage of the script to post-process building in Unity, and some basic knowledge about AppleScript.
Now comes the problem. There are plenty of web pages on the internet (including StackOverflow) about this topic, basic steps of which includes:
Get the path of the file / framework / lib you want to add to the XCode project.
Tell XCode and its inner objects to do some preparing work.
Create file references for what you want to add, and add them to the right phases.
But in the last step, difficulty comes. I follow something like
add myFileRef to compile sources phase of target 1 of project 1
and
add myFrameworkRef to link binary with libraries phase of target 1 of project 1
to really add the files, but when the script is run, these steps just throw errors like
blahblahblah doesn't understand the add message
which drives me mad. According to my searching results, this kind of things work for XCode 3 (but break in XCode 4), so could anyone here please share his/her knowledge about what I'm likely to miss in the AppleScript listed above? or is there any good alternatives to do such things programmatically?
Up till now, I've found no way of doing it with AppleScript. So, my only shot is to directly modify the Xcode project file to add what I want to add.

How to include a bundle in main project xcode 4.1

[UPDATE 03/04/2015]
The question is now 4 years old, and applies to a specific version of XCode which I have now specified in the subject.
I have searched a lot for this argument, but I couldn't find a solution, I even post on stackoverflow, but I soon deleted the question becuase of very little access.
Now I am trying again.
I have a workspace with two distinct projects A and B.
B has two targets, one that build a static library Blib.a, and one that build a bundle B.bundle. All of them get built in the derived directory.
In project A I can easily add the static library from the build phases. However I cannot find a way to include the bundle. B.bundle is not visible from "copy resource" tab in A.
Therefore I need to add manually, with all that implies.
I also thought about using a script, but I would like to use this as a very last option.
Has someone a solution for this ? Did I miss something ?
thanks
After long investigation, it came up there's no easy way of doing this. The B.bundle is never visible to A project, and there's no settings in workspace to change that.
At this point there are three solutions:
Include the bundle manually from "copy resources->other", I started with this, but everytime there's a change you have to drop and include the bundle again
Create a script to be run in build phase, if everything is built into the PRODUCTS dir you can find the bundle easily and having copied automatically into the app.bundle. This is not a bad solution. If you are using svn the script got included in project, and users have it for free without additional work.
As suggested by Apple tech support, use folder references.Build bundle B into a folder and add such folder to project A using the "Create Folder References for any added folders" option. Xcode 4 will update your bundle into that folder every time you built it.
The added folder will appear as blue once included in your project A.
Thats's it, I personally use the script, because this solution is path independent if you use standard xcode reference variable such as BUILT_PRODUCTS_DIR and so on, and the shell script is just a cp -r-f
[UPDATE 03/04/2015]
I would like to point out that the question is now 4 years old. At that time there weren't many "official" options available. I even spoke with Apple Tech Support, which proposed solution 3 as the only available solution. It is of course very likely that things are now changed, and there is a much better solution. Just to speak, I also like to add that the three above are not "hacks" but "solutions", maybe technically outdated, but they can still be used nowadays. I intend a "hack" as a..."hack", which means it probably not going to work in future software release.
Here is how I did it.
Drag and drop B.bundle from Project B → Products → B.bundle into the Copy Bundle Resources build phase of your app in Project A (select the Create groups options when asked). This will add B.bundle at the root of your Project A outline. You can move it into the Frameworks directory near Blib.a if it you prefer.
Select B.bundle and check its Location in the Identity and Type right panel (Utilities area). By default, Xcode chooses Relative to Project. This is wrong, select Relative to Build Products instead.
The path to B.bundle will now look something like ../../../../../../../../Projects/MyApp/B.bundle. This is not what you want, but you can easily fix it. Open ProjectA.xcodeproj/project.pbxproj in a text editor, search for this path and delete everything in it except for B.bundle. Your project.pbxproj should look like this:
explicitFileType = wrapper.cfbundle; name = B.bundle; path = "B.bundle"; sourceTree = BUILT_PRODUCTS_DIR; };
Save your project.pbxproj file. Xcode will automatically reload your project and your app should build just fine.
After searching for a long time and failing many times, I found this resource that has been an absolutely great tutorial to create Static Libraries and include bundles in your main project or even for distribution to 3rd party developers that may consume your library.
Absolutely recommended:
https://github.com/jverkoey/iOS-Framework
In project A, is the product of project B a dependency in your scheme's Build action? I think you might have to set up this dependency (sometimes disabling the automatic dependency discovery option is best) for it to show up and be available for copying into another target. I believe this is because it doesn't really exist (like an image resource file) until it's built and Xcode needs to ensure it's built before working with it from another target.
As of Xcode 5.1.1 I was able to drag and drop B.bundle from the Project Navigator to the Copy Bundle Resources list of project A Build Phases. I assume creating B.bundle target is not an issue.
Switch build to Generic iOS Device. This step is needed to create a non-simulator reference.
Drag the .bundle to the other project's Copy Bundle Resources.
Select the .bundle in the Project navigator of the other project, and change its Location to Relative to Build Products
Make sure your .bundle in added to Target Dependencies of your static library

Xcode 3.1.1 and static libraries

I'm an experienced VS.NET user and trying to get up and running on Xcode 3.1.1.
Here's what I'm trying to accomplish:
I'd like a static library ("Lib") to have its own xcodeproj file. I'd an executable application ("App") that makes use of Lib to reference Lib's xcodeproj file so that changes to Lib cause App to relink. Ideally, I'd like to be able to edit Lib's source files inside App's Xcode workspace so I don't have to task around all the time to make changes.
I figured out from the online help that I can simply drag the static lib xcodeproj in to my app's project and it gets the reference. I see that once my static lib xcodeproj is in my app's project, I can simply drag it to the App's target and it understands that App depends on Lib. This seems like the right path, but things aren't quite working the way I'd like yet.
Here are my questions:
It seems that simply having App depend on Lib doesn't cause App to link with Lib. It seems that I have to explicitly drag libLib.a from the Lib folder into App's "Link Binary With Libraries" build stage. In VS.NET, simply specifying the project as a solution dependency adds it to the link line. I just want to make sure I'm not missing anything.
When I have App open in Xcode and I drag Lib.xcodeproj into it, I don't get any of Lib's source files there. I only get libLib.a under the "Lib.xcodeproj" folder. In VS.NET, I can edit Lib's source files right there and rebuild it, etc... but with this approach in Xcode, changes to Lib.cpp don't cause Lib to rebuild when I rebuild App. Ideally, I'd get all of Lib's source files and targets to show up when I drag Lib.xcodeproj into App. Is there any way of doing this?
Thanks in advance for any responses!
You're correct that making target A depend upon target B (whether within the same project or across projects) does not cause target A to link against target B. You need to specify them distinctly; this is because they're separate concepts, and you might have dependencies between targets that you don't want to link to each other — for example, a command-line tool that gets built by target C and is used as part of the build process for target A.
Also, you're correct that referencing project B from within project A will not let you see project B's source code in project A's window. That's because Xcode does not have the same "workspace" model that Visual Studio and Eclipse do; you above alluded to the existence of "a workspace containing project A" but Xcode doesn't really have any such thing, just a window representing project A.
Open the App project. Right-click on the App target and choose "Get Info." Then go to the "General Tab" and find "Direct Dependencies." Click the ( + ) (plus sign) button to add a direct dependency. The Lib.xcodeproj should appear among a list of possibilities for you. Choose the Lib target from that list.
That should accomplish that the Lib project must build (or rebuild) when you build the App target.
(Editing my own post now. I realize I said nothing about point number 2 in the question. I am actually still thinking about number 2. I am not sure if that is possible or not.)
I'm also novice to Xcode 3.1, just played with mentioned by you issues and found that there is no problem regarding to your second question. Whatever application you use to edit the dependence library source code, your main project will rebuild the dependence target. I checked it by:
edited the source file, of the library your app depend on, by notepad application.
Selected dependence library project reference, mouse right-click, and select 'Open With Finder', then selected wanted source file and edited it.
Everything working well.
I am also a fairly new user of Xcode. Most of what I know I learned from an Xcode book by James Bucanek (ISBN 047175479x). It is an older book that was written for/with Xcode 2.2, but I find that pretty much all of it still applies for me today, and I currently use Xcode 3.1
You can probably find a cheap used copy if you are interested.

Resources