Xcode template <<date>> format
Asked Answered
D

3

10

I'm working up a custom Xcode template, and I'd like to change the way <<date>> is formatted.

For example:

//  Created by «FULLUSERNAME» on «DATE».
//  Copyright «YEAR» «ORGANIZATIONNAME». All rights reserved.

if the file was created today would fill as:

//  Created by SooDesuNe on 2/24/2010.
//  Copyright 2010 MyOrganization. All rights reserved.

Dates formatted in any "all numbers" format can cause a lot of confusion, since the ISO and JIS way of writing the same date is 24/2/2010. It's clear on the 24th day of the month, but not so clear on the first 12 days of the month.

I would like x-code to populate <<date>> like:

//  Created by SooDesuNe on 24-Feb-2010.
//  Copyright 2010 MyOrganization. All rights reserved.

Since there is no ambiguity that way. Anyone know how to change the date format?

Disassemble answered 25/2, 2010 at 3:11 Comment(0)
T
13
defaults write com.apple.dt.xcode AppleICUDateFormatStrings '{ 1 = "d-MMM-y"; }'
Taka answered 25/2, 2010 at 4:21 Comment(5)
Copied that into the terminal, and created a new file from my template. But the date formate was still mm/dd/yyDisassemble
That got it, thanks! Where is that type of information documented?Disassemble
It isn't. The date formats are from ICU, which OS X has used for a while; I just configured the format for myself in Date & Time System Preferences then did a 'defaults read -g' to see where it was written. Global defaults with a particular key are shadowed by the corresponding application defaults, which allows this to work.Taka
Not working on Xcode 9, even after a full system restartGranary
Xcode's bundle identifier has changed, so com.apple.xcode won't work any more; use com.apple.dt.Xcode. In general there is a new much more flexible system for file templates in Xcode 9; see for more information: oleb.net/blog/2017/07/xcode-9-text-macros (unfortunately all you get is a date or year though; you can't specify a date format inline from what I am aware). Also note that custom date formats have migrated into Language & Region Preferences under the Advanced… button.Taka
R
7

You can just change your short format of your time displaying in system preferences., then restart xcode, the default date format will be changed

Raymund answered 7/3, 2011 at 6:51 Comment(1)
From my observation it looks like Xcode's settings in ~/Library/Preferences/com.apple.Xcode.plist are overridden by system's time and date settings, so your solution worked for me after restarting Xcode.Jac
A
2

If you want to show the default Date and User name you can add these two lines in your ___FILEBASENAME___.swift file

// ___FILEBASENAMEASIDENTIFIER___
// Created by ___FULLUSERNAME___ on ___DATE___.

This will show the File name and created by the User and Current date.

However if you want to add the header you can add the below line

//___FILEHEADER___

Result will be:-

//
//  TestViewController.swift
//  MyProjectName
//
//  Created by Rashid on 28/12/2021.
// 
Asthenia answered 27/7, 2021 at 8:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.