美文网首页Xcode/Swift
自定义xcode模板,自定义文本宏

自定义xcode模板,自定义文本宏

作者: A_rcher34 | 来源:发表于2020-07-09 20:17 被阅读0次

写项目时间久了,就会有一些固定的格式。每次新建文件的时候,重新去写一遍,就会显得繁琐而且耽误时间。自定义xcode模板,刚好可以解决这个问题。

首先介绍一下模板的位置
iOS 平台模版的位置:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates
watchOS 平台的模版位置:
/Applications/Xcode.app/Contents/Developer/Platforms/WatchOS.platform/Developer/Library/Xcode/Templates
tvOS 平台的模版位置:
/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVOS.platform/Developer/Library/Xcode/Templates
macOS 平台文件模版的位置:
/Applications/Xcode.app/Contents/Developer/Library/Xcode/Templates

一、创建名为IDETemplateMacros.plist 的文件

在此plist文件中设置的key-value对,可用在自定义模板中,当做变量。

注意:

  • 不同位置具有不同的影响范围。
  • IDETemplateMacros.plist文件可以放置到以下几个位置中的任何一个。但是建议只放置在一个地方。
  • 当存在多个IDETemplateMacros.plist文件时,Xcode只会使用最先找到的IDETemplateMacros.plist。
  • Project user data位置:
    <ProjectName>.xcodeproj/xcuserdata/[username].xcuserdatad/IDETemplateMacros.plist
    影响范围:对当前 Project 指定的用户(username)创建的文件有影响

  • Project shared data位置:
    <ProjectName>.xcodeproj/xcshareddata/IDETemplateMacros.plist
    影响范围:对当前 Project 的所有成员创建的文件有影响

  • Workspace user data位置:
    <WorkspaceName>.xcworkspace/xcuserdata/[username].xcuserdatad/IDETemplateMacros.plist
    影响范围:对当前的 Workspace 下的指定的用户(username)创建的文件有影响

  • Workspace shared data位置:
    <WorkspaceName>.xcworkspace/xcshareddata/IDETemplateMacros.plist
    影响范围:对当前 Workspace 下的所有成员创建的文件有影响

  • User Xcode data位置:
    ~/Library/Developer/Xcode/UserData/IDETemplateMacros.plist
    影响范围:对当前 Xcode 创建的文件都有影响

二、用户自定义模板位置

~/Library/Developer/Xcode/Templates
可以从文章开头平台模板的位置,拷贝一份放入自定义模板的位置,并做自己想要的添加或者修改。

新加模板的位置
新加模板在finder中的样子

新建文件时,父类名称的联想补全,是根据文件夹的名字补全的。新建文件的默认显示内容,则根据最右侧的swift文件内容来显示。


相关文章

网友评论

    本文标题:自定义xcode模板,自定义文本宏

    本文链接:https://www.haomeiwen.com/subject/phxughtx.html