代碼塊
- 書寫代碼
@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/
自定義文件頭部注釋
- 創(chuàng)建 IDETemplateMacros.plist 文件
- 添加宏名稱 FILEHEADER
- 添加宏對應(yīng)的值,即自定義的注釋格式
DATE:現(xiàn)在的日期
FILENAME:所在文件的全名
ORGANIZATIONNAME:機構(gòu)名稱,在配置文件中獲取
PACKAGENAME:包名
PRODUCTNAME:應(yīng)用名稱
PROJECTNAME:工程名
TIME:時間
FULLUSERNAME:用戶名吗冤,為當(dāng)前MasOS的用戶賬號名
WORKSPACENAME:工作區(qū)名稱
YEAR:當(dāng)前年份
COPYRIGHT:版權(quán)字符串,由機構(gòu)名稱和創(chuàng)建年份構(gòu)成九府,例如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/ - 適用于整個工作區(qū)(個人)
<WorkspaceName>.xcworkspace/xcuserdata/[username].xcuserdatad/ - 適用于整個工作區(qū)(共享)
<WorkspaceName>.xcworkspace/xcshareddata/ - 適用于整個Xcode
~/Library/Developer/Xcode/UserData/
FILEHEADER宏的系統(tǒng)設(shè)置探究
通過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 下創(chuàng)建 Custom 文件夾
創(chuàng)建 Custom View.xctemplate 文件夾侄旬,從Source文件夾下面的 Cocoa Touch Class.xctemplate 中復(fù)制 TemplateInfo.plist 文件過來進行修改肺蔚。并添加 TemplateIcon.png(5757) 和 TemplateIcon@2x.png(114114)。
-
在Options中有Item0-Item3四個配置儡羔,對應(yīng)的是我們創(chuàng)建文件時候的四個選項宣羊,如下圖
修改 TemplateInfo.plist 文件如下璧诵,并刪除了 item3 中 swift 相關(guān)內(nèi)容
- 創(chuàng)建 UIViewXIBObjective-C 文件夾,添加
___FILEBASENAME___.xib
文件仇冯,并修改內(nèi)容
<?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
大功告成V蕖!苛坚!下面提供下 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