I'd like to make a couple of Swift file templates that I can drop into Xcode's file template picker. I know how to make a custom Playground template and Obj-C file templates but for Swift there seems to be no file template available at all in the following path:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/File Templates/Source/
This surely should be possible, shouldn't it? (Or does every app developer start with the awful default templates?)
I've created a new template folder under the path
/Users/name/Library/Developer/Xcode/Templates/File Templates/User Templates
with the name Swift File.xctemplate and the following contents:
___FILEBASENAME___.swift
TemplateIcon.png
TemplateIcon#2x.png
TemplateInfo.plist
and of course edited the files accordingly. When I open Xcode's temple chooser, my template appears but it somehow doesn't work correctly. It also opens a file browser and asks where to store the file which isn't right, and the file doesn't appear in the project afterwards.
Is there any solution to this? The web seems to be devoid of such information.
Using Xcode Version 6.1.1 (6A2008a), if you go into one of the template bundles found in /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/File Templates/Source you'll see the swift templates.
So, for example, let's open up a new Terminal window and look inside the Cocoa Touch Class.xctemplate bundle to see all the swift templates:
$ cd "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/File Templates/Source/Cocoa Touch Class.xctemplate"
$ ls *Swift
NSObjectSwift:
___FILEBASENAME___.swift
...
That should give you a good place to start looking so you can figure out what has gone wrong with your custom template.
A couple things that always help me are:
1) Check, double check, and triple check your TemplateInfo.plist file, it's the most important file in the template and the easiest to mess up.
2) Sometimes, when I can't get Xcode to recognize my new template, or changes to an existing template, then restarting the dang thing sometimes works wonders.
Related
The given version is described here: How do I rename a project in Xcode 5?
But, as you can see from the following screenshot^, not everything gets renamed, and if one opens package contents, directory names etc. to try to manually change all the references, the project is broken afterwards, so you have to keep the old project name for sub directories etc., which granted is not a massive problem, but is intensely irritating, and I'm not enjoying being intensely irritated at work.
^ apologies for a screenshot, but there's too much information in it to transcribe to written text. Top two-thirds of screenshot is XCode project, bottom third a Finder window.
Renaming projects in xcode in one of the most annoying things in iOS development. I assume you want to rename your app. I faced this problem once and figured out a simple, clean way to do it.
Go back to the point where everything worked.
Open project in xcode and click on the project icon in the project structure( first file)
Go to the info tab
Search for Bundle Name. Most probably it will automatically be set to $(PRODUCT_NAME) which is a shell variable that will set your app name the same as the project name.
Set it to whatever you want your app name to be
Done
Notes :
If you use custom URL Schemes this might produce an error when redirecting.
ALWAYS git or some other SVN in your projects. This will come in handy in this kind of situations
I want to add some stuff to the built-in UIViewController template for new Projects (for example, keyboard dismissal methods). I found this question that explains how to go into the Xcode bundle, and modify a particular class template. However, when I make a new iOS Project, the particular template that I find in the iPhoneOS folder is slightly different from the one that is actually used, and of course, my modifications to the template don't take effect (after restarting Xcode to make sure). (FYI, I am selecting iOS / Single View template to start the Project.)
Then, of course, how do you protect the customizations you make from updates to Xcode? I assume when the .app bundle is overwritten by a download from the App Store, it will overwrite all the templates?
You need to create a custom Xcode project template and tell that project template to use your customized ViewController file. Creating custom project templates is a royal pain and too large a subject to cover completely in an answer here. What I can answer here is where to place your custom templates so they don't get overwritten by Xcode updates. Place your custom project templates in the following folder:
/Users/Username/Library/Developer/Xcode/Templates/Project Templates/GroupName
Where GroupName is the group name on the left side of the New Project Assistant. You can create your own group name or use one of the existing group names.
A Google search for Xcode custom project templates uncovered the following article for Xcode 7 on the first page of results:
How to Create Custom Project Templates in Xcode 7
I wrote everything I know about creating custom Xcode project templates in the following article:
Creating Custom Xcode 4 Project Templates
Really having a tough time getting Firebase stood up in xcode. I'm trying to get a project going using Swift with the instructions here.
Per the instructions I create a new project using Templates. I choose Firebase > Single View Application, which creates a project. From here I have problems.
I try to create a bridging header by first creating a temp objc file. I'm never presented with the option to actually create the bridging header during that process. Only the objc file is created. I manually create a header file using these instructions.
I note some strangely name view controller files are created which fail the build due to containing multiple syntax errors (___VARIABLE_classPrefix:identifier___ViewController.h and ___VARIABLE_classPrefix:identifier___ViewController.m).
Main.storyboard won't open. I get a message saying it is corrupt.
What is going on here? I'm able to stand up a normal non-Firebase project via templates. I'm new to Swift/XCode dev so I'm not sure if I'm missing a step. Is it possible to install this SDK via templates?
Not quite sure what you've done here lol.
Best to use this guide when new to swift.
To create a header file go to 'file' -> 'new' -> 'file' -> In the IOS tab 'Header file'.
I've been having problems with Firebase in Xcode 8 Beta so probably best to stick with Xcode 7 until official release.
Okay, here's a little bit of context:
I have just added a Mac OS Core Data Command Line Tool target to my iOS project. It's purpose is to simply use my iOS app's Core Data model and a JSON file (which I am adding default data to as I go) to create an SQLite database which I am going to use as the default database for my iOS app. The idea is to have this command line tool ready in my project so that when I add some default data to my JSON file, I just:
Run the command line tool
Go to products in the file navigator on the left
Control click the command line tool product and hit show in finder
Drag the .sqlite database that has been displayed along with all the other bundled files for my command line tool and drop it into my iOS app's resources
But, I can't do this because the command line tool product is showing red in the navigator window because Xcode is looking for it at this path:
/Users/kylejm/Library/Developer/Xcode/DerivedData/MyiOSApp-ggjlxrqiijmbqkgkucdargamkwld/Build/Products/Debug-iphoneos/
Where as the it is actually in:
/Users/kylejm/Library/Developer/Xcode/DerivedData/MyiOSApp-ggjlxrqiijmbqkgkucdargamkwld/Build/Products/Debug/
I have been inspecting the Build Locations in the Build Settings but all the resolved paths are correct for both my iOS app and the command line tool respectively.
What do I need to do to make Xcode look in the right place?
Thanks so much for any help in advance.
I just clarified my scenario/problem for the answer by bauerMusic like so:
Thanks for your answer but I don't think you quite understand my scenario or problem. The Command Line Tool (CLT) target is a part of my project, and therefore has a executable product in the product folder (shown in red until first build and run). When I run this command line tool, it's product in the products folder remains red because Xcode is looking for the product in the wrong place for it.
I've put it in the description so you all understand my question as clearly as possible.
You usually never add files to a project outside of Xcode, (meaning, simply place it in the folder) unless you want to have these sort of issues.
Try to remove it, restart the project (build and see that it has no broken links warnings), and drag the file to the navigator's folder in your open Xcode project.
Edit: Just to be clear, add through Xcode, not the Finder. Xcode should prompt you to either copy resource or not (check box).
I was going to suggest you Clean the project, but I then noticed how you actually added the file.
I am trying to import the NYXImagesKit library in to my iOS 5.1 project but it will not show up as importable code. It cannot find the library. I have dragged the NYXImagesKit library in to the project and added the libraries. I have also added the following to my build phases:
However I still get an error saying it cannot find NYXImagesKit.h when i try to import it.
NYXImagesKit can be found from here: https://github.com/Nyx0uf/NYXImagesKit
Ive used this in a previous project so I know that it works.
screenshot of location of .h file:
header search paths:
You are not having an issue with "importing" the library proper. (I would not like to appear pedantic, but a library is linked, not imported). The issue you are having is with the header file which comes with the library.
To fix it, you should make sure to add the path to NYXImagesKit.h in your project build sentting (Search Headers Path). This can by found under Build options in your project settings.
Alternatively, an easier way is to add the NYXImagesKit.h file to your project (like any .m file). Then it will be found without the need to specify an header search path.
EDIT:
Since from what you report, everything seems ok, he only idea I can come up with is making sure that the paths are defined for your target (as opposed to the project overall); but I guess it is already like that.
Other than that, only resort is thinking that the project got corrupted somehow. You can inspect the project.pbxproj file inside your .xcodeproj document with a text editor and ensure that everything looks fine.
If everything fails, just start over with a new project.