Skip to content

Instantly share code, notes, and snippets.

View gonzalezreal's full-sized avatar

Guille Gonzalez gonzalezreal

View GitHub Profile
@gonzalezreal
gonzalezreal / gist:4194038
Created December 3, 2012 10:12
Como evitar referencias circulares cuando usamos ARC con bloques
// Este código crea una referencia circular entre 'operation' y self
self.operation = [NSBlockOperation blockOperationWithBlock:^{
[self doSomething];
}];
// Para evitarlo tenemos pasarle al bloque una referencia débil a self
typeof(self) __weak w_self = self;
#import <UIKit/UIKit.h>
@class TGRTweet;
@class TGRProfileImageView;
@interface TGRTweetCell : UITableViewCell
@property (strong, nonatomic) TGRProfileImageView *profileImageView;
@property (strong, nonatomic) UILabel *nameLabel;
@property (strong, nonatomic) UILabel *dateLabel;
@gonzalezreal
gonzalezreal / gist:4007532
Created November 3, 2012 14:30
Utilizando NSFetchedResultsController
NSFetchedResultsController *frc = [[NSFetchedResultsController alloc] initWithFetchRequest:[TGRTweet fetchRequestForAllTweets]
managedObjectContext:managedObjectContext
sectionNameKeyPath:nil
cacheName:nil];
@gonzalezreal
gonzalezreal / gist:4007531
Created November 3, 2012 14:29
Utilizando NSFetchedResultsController
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = ...;
TGRTweet *tweet = [self.fetchedResultsController objectAtIndexPath:indexPath];
// Configuramos la celda usando los atributos del tweet
// ...
return cell;
}
@gonzalezreal
gonzalezreal / gist:4007527
Created November 3, 2012 14:28
Utilizando NSFetchedResultsController
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [[self.fetchedResultsController sections] count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [[[self.fetchedResultsController sections] objectAtIndex:section] numberOfObjects];
}
#import "TGRTweetCell.h"
.
.
.
- (void)viewDidLoad
{
[super viewDidLoad];
#import <UIKit/UIKit.h>
@interface TGRProfileImageView : UIView
- (void)setProfileImageURL:(NSURL *)url;
- (void)cancelCurrentImageLoad;
@end
+ (ACAccountStore *)tgr_sharedAccountStore
{
static dispatch_once_t onceToken;
static ACAccountStore *accountStore;
dispatch_once(&onceToken, ^{
accountStore = [[ACAccountStore alloc] init];
});
return accountStore;
//
// TGRProfileImageView.m
// TwitterTimeline
//
// Created by guille on 27/10/12.
// Copyright (c) 2012 Guillermo Gonzalez. All rights reserved.
//
#import "TGRProfileImageView.h"
#import "SDWebImageManagerDelegate.h"
@gonzalezreal
gonzalezreal / gist:4007534
Created November 3, 2012 14:31
Utilizando NSFetchedResultsController
- (void)controller:(NSFetchedResultsController *)controller
didChangeObject:(id)anObject
atIndexPath:(NSIndexPath *)indexPath
forChangeType:(NSFetchedResultsChangeType)type
newIndexPath:(NSIndexPath *)newIndexPath
{
// Aquí podemos utilizar los métodos de UITableView para
// actualizar nuestra tabla
}