How does Xcode know who the project was "created by"?
Asked Answered
W

6

26

Whenever a new file is added to the project, Xcode adds the following lines of comments on top.

//  Created by {my name here} on 8/4/11.
//  Copyright 2011 __{my company name here}__. All rights reserved.

How does it know what my name is? Does it assume that if my account name belongs to "Mike", "Mike" is the name of the developer writing this code?

Does it then look at Address Book trying to find out what company "Mike" works at? It would make sense, however company listed as part of my address book is not what shows up in the Xcode file.

Can one set the following up in some place where Xcode will read it from?

  • Name
  • Company name
  • some other text describing something important
Wilfredowilfrid answered 5/8, 2011 at 0:13 Comment(0)
P
28

In Address Book select yourself (or add yourself if you aren't there) and then go to Card -> Make This My Card in menu bar. The name, last name and company name from that card will be used to populate info in file headers when creating files from Xcode templates.

Alternatively, you could set it using defaults via Terminal.app like this:

defaults write com.apple.Xcode PBXCustomTemplateMacroDefinitions '{ORGANIZATIONNAME="ACME Inc.";}'
Pulliam answered 8/8, 2011 at 14:3 Comment(2)
You can only have one active at a time, but if you want you can just change the active card at any time and from that moment, Xcode will pickup the new info on all the created files.Pulliam
As of Xcode 4.4 this is not correct. It pulls the full user name (___FULLUSERNAME___ in the template files) from the Full Name field of the current user's account record in Settings > Users & Groups. The Address book card is not used. Neither does the PBXCustomTemplateMacroDefinitions value of FULLUSERNAME have any effect.Concupiscent
H
22

System Preferences --> Users & Groups --> choose Current User --> right click Current User --> Advanced Options --> change the full name It works in Xcode 6.3.2

Huffy answered 30/5, 2015 at 10:56 Comment(2)
Thank you! Been looking for an hour and this fixed it.Consecration
edit: choose Current User --> UNLOCK THE PANEL --> right click Current User (P.S.: Thanks, it works!)Blake
T
6

It uses you own information from the address book.

Got to:

System Preferences --> Users & Groups --> choose current User --> and press Open at Address Book Card.

There you will find you own information used in xcode.

Toilet answered 8/8, 2011 at 14:6 Comment(0)
W
6

The "Created by" name does not come from the Address Book, rather, it comes from the name in System Preferences -> User and Groups under "Current User". You can change this name and other variables in the file header by creating a property list file called IDETemplateMacros.plist. To change the name by where it says "Created by", create a new key called FULLUSERNAME and give it the value you wanted. To change the company name, create a new key called ORGANIZATIONNAME. You could also rewrite the whole header by creating a new key called FILEHEADER. To access macros like FULLUSERNAME and ORGANIZATIONNAME in the values for any of these keys, just surround the macro by two underscores on both ends. (Example: Key: FILEHEADER, Value: Made by __FULLUSERNAME__)

For where to put the plist file, refer to step 3 from Ole Begemann's blog post about macros,

Copy the file to one of the following locations. The directory specifies in which context the customized text macros should be applied:

  • For a single project and user: .xcodeproj/xcuserdata/[username].xcuserdatad/IDETemplateMacros.plist

  • For all team members in a single project: .xcodeproj/xcshareddata/IDETemplateMacros.plist

  • For all projects in a workspace for a single user: .xcworkspace/xcuserdata/[username].xcuserdatad/IDETemplateMacros.plist

  • For all projects in a workspace for all team members: .xcworkspace/xcshareddata/IDETemplateMacros.plist

  • For everything you work on, regardless of project: ~/Library/Developer/Xcode/UserData/IDETemplateMacros.plist

For more information, check out this great article written by Ole Begemann, https://oleb.net/blog/2017/07/xcode-9-text-macros/

Wendeline answered 5/4, 2019 at 15:3 Comment(1)
This is the best and most detailed answer; and only one that works in Xcode 14.Ferritin
S
5

The template comes from i.e. /Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/File Templates/Cocoa Touch/Objective-C class.xctemplate/NSObject/FILEBASENAME.h

You can harcode some custom info(like code warranty or other legal text). Play with it to achieve desired results, but this is the hard and clumsy way

On the easy way useful hint would be that you can change Organization property on the Utilities pane(right side) in Xcode4, when editing the project file(liek build settings). It will be applied to all files created in this project.

Scraggly answered 8/8, 2011 at 14:30 Comment(0)
S
1

I haven't checked but I think it pulls that information from your default entry in the address book.

Semi answered 5/8, 2011 at 0:29 Comment(2)
"default entry" is the one associated with your Account in System Preferences->Accounts. It also has a special icon in the Address BookGaudreau
You can find it in the "Contacts" application. Tap the "Card" menu, then "Go to My Card".Indisposed

© 2022 - 2024 — McMap. All rights reserved.