This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #import <Foundation/Foundation.h> | |
| #import <Accounts/Accounts.h> | |
| #import <CoreData/CoreData.h> | |
| @interface TGRTimeline : NSObject | |
| @property (strong, nonatomic, readonly) NSManagedObjectContext *managedObjectContext; | |
| @property (nonatomic, readonly, getter = isLoading) BOOL loading; | |
| - (id)initWithAccount:(ACAccount *)account; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #import "TGRTimeline.h" | |
| #import "TGRTweet.h" | |
| #import <Social/Social.h> | |
| @interface TGRTimeline () | |
| @property (nonatomic, readwrite) BOOL loading; | |
| @property (strong, nonatomic) ACAccount *account; | |
| @end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @implementation TGRTimeline | |
| - (id)initWithAccount:(ACAccount *)account | |
| { | |
| self = [super init]; | |
| if (self) { | |
| _account = account; | |
| } | |
| return self; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - (BOOL)loadNewTweetsWithCompletionHandler:(void (^)(NSError *error))completionHandler | |
| { | |
| if (self.loading) { | |
| return NO; | |
| } | |
| SLRequest *request = [self requestForNewTweets]; | |
| [self loadTweetsWithRequest:request completionHandler:completionHandler]; | |
| return YES; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - (SLRequest *)requestForNewTweets | |
| { | |
| return nil; | |
| } | |
| - (SLRequest *)requestForOldTweets | |
| { | |
| return nil; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - (void)loadTweetsWithRequest:(SLRequest *)request completionHandler:(void (^)(NSError *error))completionHandler | |
| { | |
| self.loading = YES; | |
| [request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) { | |
| if (!error) { | |
| id response = [NSJSONSerialization JSONObjectWithData:responseData | |
| options:0 | |
| error:NULL]; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| TGRTweet *tweet = [NSEntityDescription insertNewObjectForEntityForName:@"TGRTweet" | |
| inManagedObjectContext:self.managedObjectContext]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| TGRTweet *tweet = [TGRTweet insertNewObjectInManagedObjectContext:self.managedObjectContext]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| TGRTweet *tweet = [TGRTweet importFromDictionary:jsonTweet | |
| inManagedObjectContext:self.managedObjectContext]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"TGRTweet"]; | |
| [fetchRequest setFetchBatchSize:25]; | |
| NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"identifier" | |
| ascending:NO]; | |
| [fetchRequest setSortDescriptors:@[sortDescriptor]]; | |
| NSArray *tweets = [self.managedObjectContext executeFetchRequest:fetchRequest error:NULL]; |
OlderNewer