Skip to content

Instantly share code, notes, and snippets.

@XcqRomance
Last active August 14, 2019 12:55
Show Gist options
  • Save XcqRomance/e4c4b447557850275608e7090b8bed91 to your computer and use it in GitHub Desktop.
Save XcqRomance/e4c4b447557850275608e7090b8bed91 to your computer and use it in GitHub Desktop.
开发中Xcode常用的快捷代码块设置
// mystrong
@property(nonatomic, strong)<#propetyclass#> *<#propertyname#>;
// mycopy
@property(nonatomic, copy)<#propetyclass#> *<#propertyname#>;
// myassign
@property(nonatomic, assign)<#propetyclass#> *<#propertyname#>;
// myweak
@property(nonatomic, weak)id<<#protocalname#>> <#propertyname#>;
// mylazyload
- (<#classname#> *)<#propertyname#> {
if (!_<#propertyname#>) {
_<#propertyname#> = [[<#classname#> alloc] init]];
}
return _<#propertyname#>;
}
// myimplementation
#pragma mark - life cycle
- (instancetype)init {
if (self = [super init]) {
[self buildUI];
}
return self;
}
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
[self buildUI];
}
return self;
}
- (void)dealloc {
}
#pragma mark - private method
- (void)buildUI {
}
#pragma mark - public method
#pragma mark - event response
#pragma mark - setter && getter
// mytableviewdatasource
#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return <#count#>;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:<#cellID#> forIndexPath:<#indexPath#>];
return cell;
}
// UICollectionViewDataSource
#pragma mark - UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView
numberOfItemsInSection:(NSInteger)section {
return <#numberOfItemsInSection#>;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
cellForItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:<#reuseIdentifier#> forIndexPath:indexPath];
[self configureCell:cell forItemAtIndexPath:indexPath];
return cell;
}
- (void)configureCell:(UICollectionViewCell *)cell
forItemAtIndexPath:(NSIndexPath *)indexPath {
<# statements #>
}
// documentsDirectoryURL
NSString *documentsDirectoryPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
NSURL *documentsDirectoryURL = [NSURL fileURLWithPath:documentsDirectoryPath];
// libraryDirectoryURL
NSString *libraryDirectoryPath = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) firstObject];
NSURL *libraryDirectoryURL = [NSURL fileURLWithPath:libraryDirectoryPath];
// layzyload
- (<#classname#> *)<#propertyname#> {
if (!_<#propertyname#>) {
_<#propertyname#> = [[<#classname#> alloc] init];
}
return _<#propertyname#>;
}
// NSCoding
#pragma mark - NSCoding
- (instancetype)initWithCoder:(NSCoder *)decoder {
self = [super init];
if (self) {
<# implementation #>
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)coder {
<# implementation #>
}
// singleton
+ (instancetype)shared<#name#> {
static <#class#> *_shared<#name#> = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_shared<#name#> = <#initializer#>;
});
return _shared<#name#>;
}
// tableView
- (UITableView *)tableView {
if (!_tableView) {
_tableView = [[UITableView alloc] initWithFrame:<#frame#>];
_tableView.dataSource = self;
_tableView.delegate = self;
[_tableView registerClass:[<#cellname#> class] forCellReuseIdentifier:<#cellID#>];
}
return _tableView;
}
// myUITableViewDataSource
#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return <#number#>;
}
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section {
return <#number#>;
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:<#reuseIdentifier#> forIndexPath:indexPath];
[self configureCell:cell forRowAtIndexPath:indexPath];
return cell;
}
- (void)configureCell:(UITableViewCell *)cell
forRowAtIndexPath:(NSIndexPath *)indexPath {
<#statements#>
}
// myviewDidAppear
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
}
// myviewDidDisappear
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
}
// myviewWillAppear
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
}
// myviewWillDisappear
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
}
// myweakSelf
__weak typeof(self)weakSelf = self;
// mystrongSelfs
__strong __typeof(<#weakSelf#>)strongSelf = <#weakSelf#>;
// mydocumentsDirectoryURL
NSString *documentsDirectoryPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
NSURL *documentsDirectoryURL = [NSURL fileURLWithPath:documentsDirectoryPath];
// mylibraryDirectoryURL
NSString *libraryDirectoryPath = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) firstObject];
NSURL *libraryDirectoryURL = [NSURL fileURLWithPath:libraryDirectoryPath];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment