代码块
- 书写代码
@property (nonatomic, copy) NSString *<#name#>;
-
选中代码右键,选择 Create Code Snipped
-
编辑代码块信息
Xcode的自带代码模板是用一个plist格式xml文件描述的,存储在Xcode的安装目录:
/Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Versions/A/Resources/SystemCodeSnippets.codesnippets
自定义的代码块路径:
~/Library/Developer/Xcode/UserData/CodeSnippets/
自定义文件头部注释
- 创建 IDETemplateMacros.plist 文件
- 添加宏名称 FILEHEADER
- 添加宏对应的值,即自定义的注释格式
DATE:现在的日期
FILENAME:所在文件的全名
ORGANIZATIONNAME:机构名称,在配置文件中获取
PACKAGENAME:包名
PRODUCTNAME:应用名称
PROJECTNAME:工程名
TIME:时间
FULLUSERNAME:用户名,为当前MasOS的用户账号名
WORKSPACENAME:工作区名称
YEAR:当前年份
COPYRIGHT:版权字符串,由机构名称和创建年份构成,例如Copyright © 2019 CY. All rights reserved.
**************************************************************************************
// _(\_/)
// ,((((^`\
// (((( (6 \
// ,((((( , \
// ,,,_ ,((((( /"._ ,`,
// ((((\\ ,... ,(((( / `-.-'
// ))) ;' `"'"'""(((( (
// ((( / ((( \
// )) | |
// (( | . ' |
// )) \ _ ' `t ,.') File name: ___FILENAME___
// ( | y;- -,-""'"-.\ \/
// ) / ./ ) / `\ \ Author: ___FULLUSERNAME___
// |./ ( ( / /'
// || \\ //'| Created on: ___DATE___
// || \\ _//'||
// || )) |_/ || Description: <#功能描述#>
// \_\ |_/ ||
// `'" \_\
// `'"
//***************************************************************************************
/*
*
* █████▒█ ██ ▄████▄ ██ ▄█▀ ██████╗ ██╗ ██╗ ██████╗
* ▓██ ▒ ██ ▓██▒▒██▀ ▀█ ██▄█▒ ██╔══██╗██║ ██║██╔════╝
* ▒████ ░▓██ ▒██░▒▓█ ▄ ▓███▄░ ██████╔╝██║ ██║██║ ███╗
* ░▓█▒ ░▓▓█ ░██░▒▓▓▄ ▄██▒▓██ █▄ ██╔══██╗██║ ██║██║ ██║
* ░▒█░ ▒▒█████▓ ▒ ▓███▀ ░▒██▒ █▄ ██████╔╝╚██████╔╝╚██████╔╝
* ▒ ░ ░▒▓▒ ▒ ▒ ░ ░▒ ▒ ░▒ ▒▒ ▓▒ ╚═════╝ ╚═════╝ ╚═════╝
* ░ ░░▒░ ░ ░ ░ ▒ ░ ░▒ ▒░
* ░ ░ ░░░ ░ ░ ░ ░ ░░ ░
* ░ ░ ░ ░ ░
*
* File name: ___FILENAME___
* Author: ___FULLUSERNAME___
* Created on: ___DATE___
* Description: <#功能描述#>
*/
- 将 .plist 文件放置到特定的目录
- 适用于整个工程(个人)
<ProjectName>.xcodeproj/xcuserdata/[username].xcuserdatad/ - 适用于整个工程(共享)
<ProjectName>.xcodeproj/xcshareddata/ - 适用于整个工作区(个人)
<WorkspaceName>.xcworkspace/xcuserdata/[username].xcuserdatad/ - 适用于整个工作区(共享)
<WorkspaceName>.xcworkspace/xcshareddata/ - 适用于整个Xcode
~/Library/Developer/Xcode/UserData/
FILEHEADER宏的系统设置探究
通过Xcode ▸ Contents ▸ Developer ▸ Platforms ▸ iPhoneOS.platform ▸ Developer ▸ Library ▸ Xcode ▸ Templates路径,然后搜索Cocoa Touch Class.xctemplate,以其中的NSObjectObjective-C文件为例
自定义类模板
在路径:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/File Templates 下创建 Custom 文件夹
创建 Custom View.xctemplate 文件夹,从Source文件夹下面的 Cocoa Touch Class.xctemplate 中复制 TemplateInfo.plist 文件过来进行修改。并添加 TemplateIcon.png(5757) 和 TemplateIcon@2x.png(114114)。
-
在Options中有Item0-Item3四个配置,对应的是我们创建文件时候的四个选项,如下图
修改 TemplateInfo.plist 文件如下,并删除了 item3 中 swift 相关内容
- 创建 UIViewXIBObjective-C 文件夹,添加
___FILEBASENAME___.xib
文件,并修改内容
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="13142" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15704"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view contentMode="scaleToFill" id="iN0-l3-epB" insetsLayoutMarginsFromSafeArea="NO" customClass="___FILEBASENAME___">
<rect key="frame" x="0.0" y="0.0" width="300" height="200"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
<point key="canvasLocation" x="65" y="-200"/>
</view>
</objects>
</document>
- 添加
___FILEBASENAME___.h
与___FILEBASENAME___.m
文件
//___FILEHEADER___
___IMPORTHEADER_cocoaTouchSubclass___
NS_ASSUME_NONNULL_BEGIN
@interface ___FILEBASENAMEASIDENTIFIER___ : ___VARIABLE_cocoaTouchSubclass___
- (void)configViewWithModel:(id)model;
@end
NS_ASSUME_NONNULL_END
//___FILEHEADER___
#import "___FILEBASENAME___.h"
@interface ___FILEBASENAMEASIDENTIFIER___ ()
@end
@implementation ___FILEBASENAMEASIDENTIFIER___
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (!self) return nil;
return self;
}
+ (instancetype)loadFromNib {
NSArray *nibs = [[NSBundle mainBundle] loadNibNamed:NSStringFromClass([self class]) owner:nil options:nil];
if ([nibs count] == 0) {
return nil;
}
return nibs.firstObject;
}
- (void)awakeFromNib {
[super awakeFromNib];
}
- (void)layoutSubviews {
[super layoutSubviews];
}
#pragma mark - Action
#pragma mark - Getter && Setter
@end
大功告成!!!下面提供下 UIViewController 的模板。
//___FILEHEADER___
#import "___FILEBASENAME___.h"
@interface ___FILEBASENAMEASIDENTIFIER___ ()
@end
@implementation ___FILEBASENAMEASIDENTIFIER___
#pragma mark - LifeCycle
- (void)viewDidLoad {
[super viewDidLoad];
[self configUI];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
}
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
}
#pragma mark - Config UI
- (void)configUI {
}
#pragma mark - Action
#pragma mark - NetWork
#pragma mark - Overwirte
#pragma mark - Public
#pragma mark - Private
#pragma mark - Getter && Setter
@end