how to set default name & company name on comments in Xcode? - iphone

When we add a new file,
In .h & .m file, there is always a comments/documentation section at top.
example.
//
// SimpleGameAppDelegate.m
// SimpleGame
//
// Created by hbmac2 on 01/10/09.
// Copyright __MyCompanyName__ 2009. All rights reserved.
//
Here, there is by default hbmac2 - is user name & MyComapnyName is also default.
Can't we set it like,
Created by Sagar -
HiddenBrains.com - by default?
Can we set any other comments to be there by default?

Nall's answer is good, but you should know that in Snow Leopard XCode you can set the Organization name (the name used by the templates) in the General tab of project settings.
If you are working on only your own stuff, you should set it once via the other means. If you are working for clients you should use the per-project setting so a file always gets the right name as you switch between projects.

1) In 3.0 and later, set your Company Name in your personal Address Book card.
2) In 3.2 and later, you can additionally have a per-project Company Name set in the Project's General tab in Get Info.

See this question for copyright: Setting copyright statement on a per-project basis?
See this question for templates: Change templates in Xcode
Another one: XCode: What do I have to type into the Terminal, in order to change the copyright notice in code templates?

Related

Preventing a CoreData crash for upgrading users

I built an app about a year and a half ago that I'm coming back to. It was the project I cut my Swift teeth on and obviously a lot has changed since then, both in the language and my Swift abilities.
Yesterday for the first time, I updated my single CoreData model to add an optional string attribute. I did the file generation bit and made sure in the inspector column the new data model is appropriately selected.
On my Simulator and testing devices, I need to delete the old version of the app to install the new version or I get a crash. I assume that's just part of the development environment process. How can I ensure that upgrading users won't have to delete and reinstall when they do a simple update from the App Store? I assume that Xcode/CoreData/Apple have this handled with some internal scripts or processes that are invisible to the user, "it just works." But I wanted to post this here to understand if there's anything additional I need to do to ensure a smooth transition from v1 to v1.1 for the user.
All I did was an an optional string column, as I mentioned. I assume that all existing user data will be migrated over to the new schema with the new field being nil.
Any thoughts here would be very welcomed and appreciated. Thanks!
If your app is crashing in the Simulator when upgrading, your users will have crashes too.
To avoid this, you need to make sure you follow these steps:
Make sure you do NOT change the original version of your data model in any way.
In Xcode, select your xcdatamodel file, then from the menu choose Editor > Add Model Version...
Xcode will suggest a new version name, based on the current model. Make a mental note of the new version name, then click Finish.
Select the xcdatamodel file again, go to File inspector and under Model Version, select the new version name to make this your current version.
In Project Navigator, select the new version of the xcdatamodel. Add your attribute.
It's important to follow these steps in this order. If you add your attribute before creating the new model or making it your current version, you will have crashes.
EDIT: This will only work if you enable lightweight migrations. This is a code snippet of how to do this:
let options = [NSMigratePersistentStoresAutomaticallyOption: true, NSInferMappingModelAutomaticallyOption: true]
do {
//coordinator is an NSPersistentStoreCoordinator
try coordinator!.addPersistentStore(ofType: NSSQLiteStoreType, configurationName: nil, at: url, options: options
} catch var error as NSError {
// handle error however you want here...
abort()
}
In addition to #Mike Taverne's answer, I think it a better if I post some screenshots to illustrate the option
for Xcode 12.3
Choose from the main menu Editor -> Add Model Version
To add mark the New Model as the current model with a green checkmark
Follow the below image

How to configure iPhone/iPad file associations with Xcode 4.3?

Can anyone provide a pointer to an updated tutorial/example of setting up custom file associations on iOS using Xcode 4.3?
I've seen the following (including Brad Larson's excellent answer), but the handling of Info.plist in Xcode 4.3 is significantly different than any description I've seen:
How do I associate file types with an iPhone application?
Importing/Exporting Documents on iOS
How to register an app to respond to a custom URL scheme opening request?
I tried reviewing Apple's documentation, but "Document Interaction Programming Topics for iOS" was updated in Nov-2010.
None of the examples I can find discuss configuring it in the way Xcode 4.3 handles them - which includes separate "Document Type", "Exported UTIs", "Imported UTIs", and "URL Types" sections under the target/Build Info and includes different key names (e.g. "Description" vs. "UTTypeDescription")
Any pointers are helpful, a working Xcode 4.3 example would be fantastic.
Based on suggestions by #samson but I wanted to capture this answer for future searchers.
Find the info.plist in the Project Navigator. Mine was under a "Supporting Files" group prepended by the application name (e.g. MyApp-Info.plist). Right-click and "Open As > Property List".
Then by entering the described sections as follows I was able to be passed a fileURL from Mail:
I should note a couple things for the record:
I did NOT put document icons for my file type, but it would be strongly encouraged to do so.
The property editor will try to auto-complete the names of properties, so it really gives you quite a bit more guidance than is apparent.

Is there a way to change bracket placement and indentation in Xcode?

I want to change the default behavior of XCode (4) for aligning brackets from this:
- (BOOL)someValue {
return _someValue;
}
To this:
- (BOOL)someValue
{
return _someValue;
}
I've reviewed the docs here:
http://developer.apple.com/library/ios/#documentation/DeveloperTools/Reference/XcodeUserDefaultRef/100-Xcode_User_Defaults/UserDefaultRef.html#//apple_ref/doc/uid/TP40005535-CH3-SW57
But I still dont' understand how to make the change. Any help?
First off, the documentation you referred to is for XCode 3.1 (I've linked the introduction page which says so clearly). Judging by the number of comments on devforums.apple.com about this, I think the XCCodeSenseFormattingOptions key no longer exists under the new XCode4 defaults (which are stored under bundle ID com.apple.dt.XCode). If you want this particular feature restored, file a bug with Apple.
Secondly, you might be able to do what you're looking for by modifying templates. I discovered this very related question, but there's no tacit confirmation there that the suggestion actually succeeded.
You could try using an application called Snippet Edit that allows you to easily edit all of the supplied code snippets. You will need to be using Xcode v4.3 or later though if you wish to use it.
The application can be found at http://cocoaholic.com/snippet_edit/

How can I configure my iPhone project to use a seperate application icon for beta releases

What I am trying to achieve is for the application icon to be different in builds that I send out to my beta testers, to that of the application that will be submitted for approval. This will allow me and my beta testers to easily identify the app is a beta version.
I was not sure if I should be adding a build script to modify the info.plist and change the application icon specified there. For this I guess I would have to conditional check the build type (DEBUG/RELEASE/DISTRIBUTION etc) and write the appropriate value to the plist file.
Alternatively I thought I might need to create a separate target for beta releases and specify the new BETA application icon there.
If anyone has done this kind of procedure before, any tips and ideas about how best to do it would be very much appreciated.
Outdated: As of September 2017, my answer is probably outdated now. Please use latest Apple developer guides relating to Asset Catalogs. Asset Catalogs are the new way of specifying image/icon resources for your app.
Original answer:
Both ways you have mentioned can be used for this purpose (Through a separate Target or using Build settings). In my opinion, the more logical way would be to use a different build configuration and set the plist file to dynamically get the icon file name from the build configuration.
Here is how I would do it:
In project build settings, create a new user-defined variable called ICON_FILE (for "All Configurations")
Set the value of the variable to "Icon.png" (for "All Configurations")
Create a new build Configuration called "Beta".
Set the value of the ICON_FILE variable to "Icon-beta.png" for "Beta" configuration.
(this will make all the configurations have the value "Icon.png" except Beta config)
In the Info.plist set the value of "Icon file" attribute to ${ICON_FILE}. This will make the info.plist dynamically get the filename from the variable you defined earlier.
In your application resources, include the beta icon with the name "Icon-beta.png" in addition to "Icon.png" you already have.
If you build the app using "Beta" config, the app will have the beta icon as the app icon.
Hope this helps!
Asset catalogs can be used without creating another target.
Here are the steps I use:
1 - Create two (or more) app icon set in images.xcassets
2 - Create another configuration from project settings
3 - Go to Target -> Build Settings and search for app icon.
You will see Asset Catalog App Icon Set Name under Asset Catalog Compiler - Options. Change the asset catalog name that will be used in new configuration.
4 - Build for different configurations.
The accepted answer is not working for xcassets.
So, if you already started to use xcassets catalog here is the steps:
You need to create 2 different targets of your application.
To do this:
Right click on your target. -> Click Duplicate (or Cmd+D)
Set name of new target like MyApp-beta
Create separate icon:
Go to your xcasset catalog.
Right click on column with list of images -> click New App Icon
Name it like icon-beta, add place here your beta icons
Click on your beta-target
Go to tab General -> App Icons -> select your asset icon-beta
Here it is. Now you can build your beta application!
Another advantage of this method over that described in the accepted answer - is that you can install both versions at the same time of your Application. (you need to set different Bundle Identifier for this).

Setting copyright statement on a per-project basis?

I'm an independent developer working primarily with iPhone applications, and I'm currently engaged in several different projects. Some are for myself, and others are for one of a number of clients. Because of this, I'd like to have a way to have Xcode set the copyright notice at the top of each source file on a per-project basis.
I've seen these questions, and I understand that Xcode by default pulls the organization on the user's Address Book contact card for the copyright statement, and that you can change the property either in the Address Book or on the terminal. What I'm looking for is a setting that lets that default be changed for each project, and has Xcode remember the copyright assignee (i.e. I don't want to have to change my Address Book organization entry each time I switch projects).
You can change the organization Xcode currently uses by issuing the following command in Terminal:
defaults write com.apple.Xcode PBXCustomTemplateMacroDefinitions '{ORGANIZATIONNAME = "Some Company Name"; }'
You can then create scripts that switch the current company for Xcode.
Upgrade to Xcode 3.2, which now has a project setting for organization name.
You might want to make custom templates. Have a look at this question:
Change templates in Xcode
look in text macros section:
Change the text used for the header of a new file by setting the value of the FILEHEADER text macro.
The example shows the default definition for the macro. Other macros are included in the definition by including three underscore (___) characters before and after the name of the macro. The line with COPYRIGHT is included only if an organization name is set.
// ___FILENAME___
// ___PACKAGENAME___
//
// Created by ___FULLUSERNAME___ on ___DATE___.
// ___COPYRIGHT___
//