記事のディレクトリ
ファイルテンプレートとは:
ファイルテンプレートは、プロジェクトの作成時にxcodeによって使用されるテンプレートです。たとえば、UIViewControllerファイルとUITableViewCellファイルを作成する場合、ファイル自体のコンテンツです。
独自のファイルテンプレートを作成する理由
開発を標準化し、毎回作成するなどの反復作業を減らします
XcodeコードブロックがUITableViewCellのアドレスを格納する場合、新しいラベル、ボタン、およびimageViewを作成することは常に避けられず、これは非常に面倒です。
作成方法
Xcodeオリジナルドキュメントテンプレート
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/File Templates / Sourceには、Cocoa TouchClass.xctemplateフォルダーにXcodeに付属している多くのファイルテンプレートがあります。 。
システムファイルテンプレートの特性を観察し、Sourceフォルダーの下に独自のファイルテンプレートのフォルダーを作成します。次の図は、自分で作成し
たファイルテンプレートです。次に、Cocoa TouchClass.xctemplateのファイルテンプレートを自分のファイルテンプレートにコピーします。フォルダ。
編集を開始する
UIViewControllerのファイルテンプレートを変更して、対応するフォルダーUIViewControllerObjective-Cを見つけたい。BaseViewControllerから継承してから、.mファイルのコード領域を分割してUmeng統計コードを記述したい。
//___FILEHEADER___
___IMPORTHEADER_cocoaTouchSubclass___
#import "BaseViewController.h"
NS_ASSUME_NONNULL_BEGIN
@interface ___FILEBASENAMEASIDENTIFIER___ : BaseViewController
@end
NS_ASSUME_NONNULL_END
//___FILEHEADER___
#import "___FILEBASENAME___.h"
@interface ___FILEBASENAMEASIDENTIFIER___ ()
@end
@implementation ___FILEBASENAMEASIDENTIFIER___
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
}
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
//开始统计
[MobClick beginLogPageView:NSStringFromClass([self class])];
}
-(void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
//结束统计
[MobClick endLogPageView:NSStringFromClass([self class])];
}
#pragma mark ---------- layout ----------
-(void)layout{
}
#pragma mark ---------- delegate ----------
#pragma mark ---------- event response ----------
#pragma mark ---------- HTTP ----------
#pragma mark ---------- private method ----------
#pragma mark ---------- getter && setter ----------
@end
以下はUITableViewCellへの変更です
//___FILEHEADER___
#import "___FILEBASENAME___.h"
@interface ___FILEBASENAMEASIDENTIFIER___ ()
@property (nonatomic, strong) UIImageView *imgView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *detailLabel;
@property (nonatomic, strong) UILabel *label1;
@end
@implementation ___FILEBASENAMEASIDENTIFIER___
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
#pragma mark ---------- setter && getter ----------
-(UIImageView *)imgView{
if(_imgView == nil){
_imgView = [UIImageView new];
}
return _imgView;
}
-(UILabel *)titleLabel{
if(_titleLabel == nil){
_titleLabel = [UILabel new];
}
return _titleLabel;
}
-(UILabel *)detailLabel{
if(_detailLabel == nil){
_detailLabel = [UILabel new];
}
return _detailLabel;
}
-(UILabel *)label1{
if(_label1 == nil){
_label1 = [UILabel new];
}
return _label1;
}
@end
plistファイルを変更します
TemplateInfo.plistのSortOrderを0に変更します。システムファイルと区別するために、フォルダー内のTemplateIcon.png画像をお気に入りに変更できます。
このカスタムファイルテンプレートは、xcodeパネルに表示できます。
通常の方法で独自のテンプレートファイルを作成できます〜
やっと
Xcodeコードブロックストレージアドレス
〜/ Library / Developer / Xcode / UserData / CodeSnippets Xcode
ファイルテンプレートの保存場所:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/File Templates / Source
このファイルはバックアップする必要があります。そうしないと、xcodeが更新されるとすぐに削除されます。