Xcode 如何知道项目是由谁“创建”的?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6950074/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How does Xcode know who the project was "created by"?
提问by James Raitsev
Whenever a new file is added to the project, Xcode adds the following lines of comments on top.
每当将新文件添加到项目时,Xcode 都会在顶部添加以下注释行。
// 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?
它怎么知道我叫什么名字?是否假设如果我的帐户名称属于“Mike”,则“Mike”就是编写此代码的开发人员的名称?
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.
然后它会查看地址簿试图找出“迈克”在哪家公司工作?这是有道理的,但是作为我地址簿一部分列出的公司并不是 Xcode 文件中显示的内容。
Can one set the following up in some place where Xcode will read it from?
可以在 Xcode 读取它的某个地方设置以下内容吗?
- Name
- Company name
- some other text describing something important
- 姓名
- 公司名
- 其他一些描述重要事情的文字
回答by Filip Radelic
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.
在地址簿中选择您自己(如果您不在,则添加您自己),然后转到菜单栏中的卡片 -> 制作我的卡片。从 Xcode 模板创建文件时,该卡片中的姓名、姓氏和公司名称将用于填充文件头中的信息。
Alternatively, you could set it using defaults via Terminal.app like this:
或者,您可以通过 Terminal.app 使用默认值设置它,如下所示:
defaults write com.apple.Xcode PBXCustomTemplateMacroDefinitions '{ORGANIZATIONNAME="ACME Inc.";}'
回答by Hongli Yu
System Preferences --> Users & Groups --> choose Current User --> right click Current User --> Advanced Options --> change the full name It works in Xcode 6.3.2
系统偏好设置 --> 用户和组 --> 选择当前用户 --> 右键单击当前用户 --> 高级选项 --> 更改全名 它适用于 Xcode 6.3.2
回答by Justin
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.
System Preferences --> Users & Groups --> choose current User --> and press Open at Address Book Card.
There you will find you own information used in xcode.
在那里你会发现你自己在 xcode 中使用的信息。
回答by Micha? Zygar
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
模板来自即/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.
简单的有用提示是,您可以在编辑项目文件(例如构建设置)时更改 Xcode4 中实用工具窗格(右侧)上的组织属性。它将应用于此项目中创建的所有文件。
回答by Chris Gong
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 FULLUSERNAMEand 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__
)
“创建者”名称并非来自地址簿,而是来自“当前用户”下“系统偏好设置”->“用户和组”中的名称。您可以通过创建一个名为
IDETemplateMacros.plist
. 要根据“创建者”的位置更改名称,请创建一个名为FULLUSERNAME的新键并为其指定所需的值。要更改公司名称,请创建一个名为ORGANIZATIONNAME的新键。您还可以通过创建一个名为FILEHEADER的新键来重写整个标题。要在任何这些键的值中访问诸如 FULLUSERNAME 和 ORGANIZATIONNAME 之类的宏,只需在宏的两端用两个下划线括起来即可。(实施例:Key: FILEHEADER, Value: Made by __FULLUSERNAME__
)
For where to put the plist file, refer to step 3 from Ole Begemann's blog postabout macros,
有关放置 plist 文件的位置,请参阅 Ole Begemann关于宏的博客文章中的第 3 步,
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
将文件复制到以下位置之一。该目录指定应在哪个上下文中应用自定义文本宏:
对于单个项目和用户:.xcodeproj/xcuserdata/[username].xcuserdatad/IDETemplateMacros.plist
对于单个项目中的所有团队成员:.xcodeproj/xcshareddata/IDETemplateMacros.plist
对于单个用户的工作区中的所有项目:.xcworkspace/xcuserdata/[username].xcuserdatad/IDETemplateMacros.plist
对于所有团队成员的工作区中的所有项目:.xcworkspace/xcshareddata/IDETemplateMacros.plist
对于您所做的一切,无论项目如何:~/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/
有关更多信息,请查看 Ole Begemann 撰写的这篇精彩文章,https://oleb.net/blog/2017/07/xcode-9-text-macros/
回答by drekka
I haven't checked but I think it pulls that information from your default entry in the address book.
我还没有检查过,但我认为它会从地址簿中的默认条目中提取该信息。