Last Updated: October 01, 2016
·
4.811K
· galex282

Xcode Code Snippets

Every time I tried to setup a UITableView I got frustrated with writing all the table view delegates, so after eons of doing this I finally discovered Code Snippets in Xcode.

  1. Write some code in Xcode,
  2. select the desired part of the code,
  3. drag and drop it into the Code Snippets Library,
  4. to reuse the code, simply drag it to your project from the library.

Here is my snippet for UITableView delegates:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return <#number of sections#>
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return <#number of rows in section#>
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return <#row height#>
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString* cellIdentifier = @"CellIdentifier";
    UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }

    cell.textLabel.text = @"";

    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

}

Picture

3 Responses
Add your response

neat!

over 1 year ago ·

The is a much better way to manage code snippets in Xcode. It is Snippets http://snippets.me/. Check out this demo http://www.youtube.com/watch?v=0qzsVhKqOHw

over 1 year ago ·

its great !!! it will save but time . but sorry to say it will make my programming skill passive.
but definitely will use for making my programming cool...

thanks

over 1 year ago ·