How to customize ViewController template file for Xcode? - ios

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

Related

Converting an existing project into customizable framework

I am a android developer and I needed to create and IOS app. So I did and app is ready now. But now I want to make it a Library/Framework. I mean a same code base will be used in different projects per client and they will be able to change the text strings and colors of app. The rest of the business logic will be remain same.
So Simply I have two major question:
How to convert the Project into Framework? Do I need to create a separate framework elsewhere and then import the project into it as Coca touch Framework? Am I right??
How to make it customizable? What I meant from Customizable is simple two things.
1) Colors of Views. I have two many views. I want A separate file of colors so that I can change color in it and it reflects changes in whole application
2) String. I want to change the text string so that it can be changed in all over the projects.
Please tell me how can I achieve these things. Specially point number two is my main concern.
Note: The project that I want to convert in framework has two many viewControllers and all are built in one storyboard.
With regard to how to create a framework, here's how I'd do it:
Create a workspace:
Bring the project you want to turn into a library into that workspace by dragging it in from the Finder (make sure it's not open in XCode when you do this). Let's call that project FrameworkProj:
Create a target for FrameworkProj of type Cocoa Touch Framework:
Create a second project, which we'll call SampleProjWhichUsesFramework, and import the framework into it.
As for your question of IB elements being settable via the framework, simply make sure you have IBOutlets for those elements that are marked public, and they will be available to SampleProjWhichUsesFramework as properties of your framework.
I think you do not have good idea of the workspace in IOS Xcode. Since in Android the workspace is dealt in another way. But there is a slight difference.
Lets me just tell you about Android and how do you made the Library and add several projects in Android studio. let say you have a Project in Android App, say App1, now you can go to menu and you can add another module as Library. That is fine and easy for you.
Now you can create another project like this, GO to new menu, here you can select New Module and then from templates you can select Phone and Table Module. let's call it App2.
Similarly you can add as many projects/app in the same project (in IOS you can think of a Workspace), and in the end, All you need to do is adding Your library project as a module dependency in All App1, App2 projects you created.
So in IOS, workspace you create at first. And then You create App1, App2 in it. You add Library (Private Framework in IOS) in same project level (same directory) Then You can add the dependency of Library into Other App1, App2 and so on other projects you created.
In this way, your codebase will remain the same for others.
You can find the whole tutorial here. It is the best I have found just give it a try.

How to distribute custom xcode templates to developers?

I am working on creating custom project templates using xcode 8.2.1. I know how to create a custom project template but my question is how do i distribute this to other developers. I cannot ask developers to copy paste the template folder i created every time in the Xcode templates path. Also maintaining template versions will be difficult. Instead is there any option to save my template code somewhere and upon clicking some installer it automatically download the dependencies and paste it in xcode template folder?
Any help is appreciated.

How to create a custom Swift File template for Xcode 6?

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.

Xcode storyboard in new ios project templates

I'm new to Xcode and Objective-c. I have the latest Xcode version, but when I create a new IOS project, regardless of the version, the generated code does not use auto property synthesis or storyboards, although I found some tutorials that says that it should use them by default. How can I change this behavior?
The easy way is to select a single view application from the list of template projects you are shown when you start a new project.
To do if from scratch you need to create a new storyboard and add the name of that storyboard to the Info Plist. See the screenshot.

Changing iOS app template

I have an app which I developed by picking "Empty application" when I started off. But now I want to change its template from empty to "Master Detail" like the Facebook, Google+ or Hike apps. Is there a straightforward method to do this or do I have to start from scratch?
Once the project has been created the template that was used to create it means nothing. It is just used to seed the project with files. Therefore, you could create a "Master-Detail Application", delete the extra frameworks, controllers, and views, and now have an "Empty Application".
The reverse is also true. You could either add the controllers or views that you now want, or you could create a second project. Once you have the second project, it may be easier to bring your current code into that project or learn from the second project and bring that into your current one.

Resources