Skip to content
This repository has been archived by the owner on Feb 2, 2022. It is now read-only.

FINAL #21

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Xcode
.DS_Store
*/build/*
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
*.xcworkspace
!default.xcworkspace
xcuserdata
profile
*.moved-aside
DerivedData
.idea/
*.hmap
Binary file added [email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
719 changes: 719 additions & 0 deletions HabraReader.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions HabraReader/Author+Create.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// Author+Create.h
// HabraReader Prototype
//
// Created by Sergey on 04.10.12.
// Copyright (c) 2012 Sergey Starukhin. All rights reserved.
//

#import "Author.h"

@interface Author (Create)

- (NSString *)description;

+ (Author *)authorWithName:(NSString *)name inManagedObjectContext:(NSManagedObjectContext *)context;

@end
41 changes: 41 additions & 0 deletions HabraReader/Author+Create.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// Author+Create.m
// HabraReader Prototype
//
// Created by Sergey on 04.10.12.
// Copyright (c) 2012 Sergey Starukhin. All rights reserved.
//

#import "Author+Create.h"

@implementation Author (Create)

- (NSString *)description {
return self.nickName;
}

+ (Author *)authorWithName:(NSString *)name inManagedObjectContext:(NSManagedObjectContext *)context {

Author *author = nil;

NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"Author"];
request.predicate = [NSPredicate predicateWithFormat:@"nickName = %@", name];
NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"nickName" ascending:YES];
request.sortDescriptors = @[sortDescriptor];

NSError *error = nil;
NSArray *authors = [context executeFetchRequest:request error:&error];

if (!authors || ([authors count] > 1)) {
// TODO: handle error
} else if (![authors count]) {
author = [NSEntityDescription insertNewObjectForEntityForName:@"Author" inManagedObjectContext:context];
author.nickName = name;
} else {
author = [authors lastObject];
}

return author;
}

@end
33 changes: 33 additions & 0 deletions HabraReader/Author.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// Author.h
// HabraReader
//
// Created by Sergey on 09.10.12.
// Copyright (c) 2012 Sergey Starukhin. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>

@class Comment, Post;

@interface Author : NSManagedObject

@property (nonatomic, retain) NSString * nickName;
@property (nonatomic, retain) NSSet *comments;
@property (nonatomic, retain) NSSet *posts;
@end

@interface Author (CoreDataGeneratedAccessors)

- (void)addCommentsObject:(Comment *)value;
- (void)removeCommentsObject:(Comment *)value;
- (void)addComments:(NSSet *)values;
- (void)removeComments:(NSSet *)values;

- (void)addPostsObject:(Post *)value;
- (void)removePostsObject:(Post *)value;
- (void)addPosts:(NSSet *)values;
- (void)removePosts:(NSSet *)values;

@end
20 changes: 20 additions & 0 deletions HabraReader/Author.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// Author.m
// HabraReader
//
// Created by Sergey on 09.10.12.
// Copyright (c) 2012 Sergey Starukhin. All rights reserved.
//

#import "Author.h"
#import "Comment.h"
#import "Post.h"


@implementation Author

@dynamic nickName;
@dynamic comments;
@dynamic posts;

@end
15 changes: 15 additions & 0 deletions HabraReader/Comment+Description.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// Comment+Description.h
// HabraReader
//
// Created by Sergey Starukhin on 22.12.12.
// Copyright (c) 2012 Sergey Starukhin. All rights reserved.
//

#import "Comment.h"

@interface Comment (Description)

- (NSString *)description;

@end
17 changes: 17 additions & 0 deletions HabraReader/Comment+Description.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// Comment+Description.m
// HabraReader
//
// Created by Sergey Starukhin on 22.12.12.
// Copyright (c) 2012 Sergey Starukhin. All rights reserved.
//

#import "Comment+Description.h"

@implementation Comment (Description)

- (NSString *)description {
return [NSString stringWithFormat:@"%@, %@\n\n%@", self.author, self.publicationDate, self.content];
}

@end
21 changes: 21 additions & 0 deletions HabraReader/Comment.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// Comment.h
// HabraReader
//
// Created by Sergey on 09.10.12.
// Copyright (c) 2012 Sergey Starukhin. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
#import "Message.h"

@class Author, Message;

@interface Comment : Message

@property (nonatomic) BOOL isRead;
@property (nonatomic, retain) Author *author;
@property (nonatomic, retain) Message *replyTo;

@end
20 changes: 20 additions & 0 deletions HabraReader/Comment.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// Comment.m
// HabraReader
//
// Created by Sergey on 09.10.12.
// Copyright (c) 2012 Sergey Starukhin. All rights reserved.
//

#import "Comment.h"
#import "Author.h"
#import "Message.h"


@implementation Comment

@dynamic isRead;
@dynamic author;
@dynamic replyTo;

@end
15 changes: 15 additions & 0 deletions HabraReader/Company+Create.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// Company+Create.h
// HabraReader Prototype
//
// Created by Sergey on 04.10.12.
// Copyright (c) 2012 Sergey Starukhin. All rights reserved.
//

#import "Company.h"

@interface Company (Create)

+ (Company *)companyWithName:(NSString *)name inManagedObjectContext:(NSManagedObjectContext *)context;

@end
37 changes: 37 additions & 0 deletions HabraReader/Company+Create.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// Company+Create.m
// HabraReader Prototype
//
// Created by Sergey on 04.10.12.
// Copyright (c) 2012 Sergey Starukhin. All rights reserved.
//

#import "Company+Create.h"

@implementation Company (Create)

+ (Company *)companyWithName:(NSString *)name inManagedObjectContext:(NSManagedObjectContext *)context {

Company *company = nil;

NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:NSStringFromClass(self)];
request.predicate = [NSPredicate predicateWithFormat:@"name = %@", name];
NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"name" ascending:YES];
request.sortDescriptors = @[sortDescriptor];

NSError *error = nil;
NSArray *companies = [context executeFetchRequest:request error:&error];

if (!companies || ([companies count] > 1)) {
// TODO: handle error
} else if (![companies count]) {
company = [NSEntityDescription insertNewObjectForEntityForName:NSStringFromClass(self) inManagedObjectContext:context];
company.name = name;
} else {
company = [companies lastObject];
}

return company;
}

@end
17 changes: 17 additions & 0 deletions HabraReader/Company.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// Company.h
// HabraReader
//
// Created by Sergey on 09.10.12.
// Copyright (c) 2012 Sergey Starukhin. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
#import "GenericHub.h"


@interface Company : GenericHub


@end
15 changes: 15 additions & 0 deletions HabraReader/Company.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// Company.m
// HabraReader
//
// Created by Sergey on 09.10.12.
// Copyright (c) 2012 Sergey Starukhin. All rights reserved.
//

#import "Company.h"


@implementation Company


@end
53 changes: 53 additions & 0 deletions HabraReader/CoreDataTableViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//
// CoreDataTableViewController.h
//
// Created for Stanford CS193p Fall 2011.
// Copyright 2011 Stanford University. All rights reserved.
//
// This class mostly just copies the code from NSFetchedResultsController's documentation page
// into a subclass of UITableViewController.
//
// Just subclass this and set the fetchedResultsController.
// The only UITableViewDataSource method you'll HAVE to implement is tableView:cellForRowAtIndexPath:.
// And you can use the NSFetchedResultsController method objectAtIndexPath: to do it.
//
// Remember that once you create an NSFetchedResultsController, you CANNOT modify its @propertys.
// If you want new fetch parameters (predicate, sorting, etc.),
// create a NEW NSFetchedResultsController and set this class's fetchedResultsController @property again.
//

#import <UIKit/UIKit.h>
#import <CoreData/CoreData.h>

@interface CoreDataTableViewController : UITableViewController <NSFetchedResultsControllerDelegate>

// The controller (this class fetches nothing if this is not set).
@property (strong, nonatomic) NSFetchedResultsController *fetchedResultsController;

// Causes the fetchedResultsController to refetch the data.
// You almost certainly never need to call this.
// The NSFetchedResultsController class observes the context
// (so if the objects in the context change, you do not need to call performFetch
// since the NSFetchedResultsController will notice and update the table automatically).
// This will also automatically be called if you change the fetchedResultsController @property.
- (void)performFetch;

// Turn this on before making any changes in the managed object context that
// are a one-for-one result of the user manipulating rows directly in the table view.
// Such changes cause the context to report them (after a brief delay),
// and normally our fetchedResultsController would then try to update the table,
// but that is unnecessary because the changes were made in the table already (by the user)
// so the fetchedResultsController has nothing to do and needs to ignore those reports.
// Turn this back off after the user has finished the change.
// Note that the effect of setting this to NO actually gets delayed slightly
// so as to ignore previously-posted, but not-yet-processed context-changed notifications,
// therefore it is fine to set this to YES at the beginning of, e.g., tableView:moveRowAtIndexPath:toIndexPath:,
// and then set it back to NO at the end of your implementation of that method.
// It is not necessary (in fact, not desirable) to set this during row deletion or insertion
// (but definitely for row moves).
@property (nonatomic) BOOL suspendAutomaticTrackingOfChangesInManagedObjectContext;

// Set to YES to get some debugging output in the console.
@property BOOL debug;

@end
Loading