首页 > 解决方案 > 如何在 Xcode 中更新文件的版权信息?

问题描述

我想更改整个项目的所有版权信息。为此,我更改了版权的模板,但此更改不会影响我现有的项目文件,只会影响新创建的文件。

您知道如何更新整个项目中的所有版权信息吗?

标签: xcodecopyright-display

解决方案


I changed the template of the copyright, but this change does not affect my existing project files, only newly created files.

Right. It's like when you bend your cookie cutter into a new shape: you don't expect the cookies you've cut out previously to assume the new shape. ;-)

The templates in Xcode don't retain any association with the files that are created from them: once a file is created, it's just a plain old text file, and the templated fields like your name and the copyright year are just plain text.

Do you know how can I update all copyright information in a whole project?

I assume that we're talking here specifically about the copyright notice in the header comment of each file, like:

//
//  FirstViewController.swift
//  TestThis
//
//  Created by Marcel Gangwisch 11/19/17.
//  Copyright © 2017 Marcel Gangwisch. All rights reserved.
//

And you want to update that copyright notice to say 2018, right? Find and replace should do the job here. If you use the Find Navigator in Xcode, you can easily search using patterns, and all the files that match the pattern will be listed in the navigator.

Searching for copyright strings in Xcode

Just to be clear, remember that the copyright notice in your source code comments doesn't affect the final product at all. If you're updating the source code copyright, you'll likely also want to update any copyright notices in the product(s) you're building. That's a little less straightforward because where you display a copyright notice in your app is up to you. But you should still be able to find the relevant files by searching for the © symbol, and of course just looking at the UI in your app will probably help.

If your app is distributed through Apple's App Store, you may need to update the app description and other metadata there. Same goes for your own web site, and also Github or whatever code repository you use.

But I would also like to restore some copyright information - so with the date, when the file was created, which I dont have.. - so I thought xcode can do some magic here

The current Xcode template does include a separate line for creation date, and if your files have that, changing the copyright year shouldn't affect the creation date line. If you need to preserve the existing year, you can again use regular expressions, and this time insert the matched pattern. For example, if you want to add an "Original copyright xxxx" comment line, you could do this:

Using a capture group

That adds a line break at the end of the first line, and then adds a second line that re-uses the captured year.


推荐阅读