Giter VIP home page Giter VIP logo

flix's People

Stargazers

 avatar

Watchers

 avatar

Forkers

sarahtamayao

flix's Issues

Feedback!

Awesome job! I can see you learning the material as you progress via your commenting. Your logic is sound, with no obvious anti-patterns. Good job also with committing often & clearly stating what each commit does!

You're doing a lot of things right, so I'm mostly going to walk through ways to improve your code quality. Since this feedback is coming the day your last assignment is due (this is my fault), I'm not going to expect this feedback to be part of Twitter โ€” but cleaning up some things before final submission is always a good bet regardless :)

Refactoring

We have a lot of repetitive code, namely around error handling in network requests (and it looks like fetchMovies is exactly the same in the MoviesVC and MoviesGridVC)

if (error != nil) {
NSLog(@"%@", [error localizedDescription]);
//Creates alert if there is an error
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Connection Lost"
message:@"Please restore your Wi-fi connection to view movies."
preferredStyle:(UIAlertControllerStyleAlert)];
// create a cancel action
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel"
style:UIAlertActionStyleCancel
handler:^(UIAlertAction * _Nonnull action) {
// No response, will dismiss view
}];
// add the cancel action to the alertController
[alert addAction:cancelAction];
// create an OK action
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * _Nonnull action) {
// handle response here.
[self fetchMovies];
}];
// add the OK action to the alert controller
[alert addAction:okAction];
//Presents alert controller
[self presentViewController:alert animated:YES completion:^{
// optional code for what happens after the alert controller has finished presenting
}];
}

if (error != nil) {
NSLog(@"%@", [error localizedDescription]);
//Creates alert if there is an error
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Connection Lost"
message:@"Please restore your Wi-fi connection to view movies."
preferredStyle:(UIAlertControllerStyleAlert)];
// create a cancel action
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel"
style:UIAlertActionStyleCancel
handler:^(UIAlertAction * _Nonnull action) {
// No response, will dismiss view
}];
// add the cancel action to the alertController
[alert addAction:cancelAction];
// create an OK action
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * _Nonnull action) {
// handle response here.
}];
// add the OK action to the alert controller
[alert addAction:okAction];
//Presents alert controller
[self presentViewController:alert animated:YES completion:^{
// optional code for what happens after the alert controller has finished presenting
}];
}

if (error != nil) {
NSLog(@"%@", [error localizedDescription]);
//Creates alert if there is an error
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Connection Lost"
message:@"Please restore your Wi-fi connection to view movies."
preferredStyle:(UIAlertControllerStyleAlert)];
// create a cancel action
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel"
style:UIAlertActionStyleCancel
handler:^(UIAlertAction * _Nonnull action) {
// No response, will dismiss view
}];
// add the cancel action to the alertController
[alert addAction:cancelAction];
// create an OK action
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * _Nonnull action) {
// handle response here.
[self fetchMovies];
}];
// add the OK action to the alert controller
[alert addAction:okAction];
//Presents alert controller
[self presentViewController:alert animated:YES completion:^{
// optional code for what happens after the alert controller has finished presenting
}];
}

One way that you can clean this up is creating a new class with class methods. For example, in the fetchMovies case, I might create something like:

FlixHelpers.h

@interface FlixHelpers : NSObject

+ (void)fetchMovies;
+ (void)networkErrorDialog;

@end

FlixHelpers.m

@implementation FlixHelpers

+ (void)fetchMovies {
    // code here
    // can call [self networkErrorDialog] here too
}

+ (void)networkErrorDialog {
   // code here
}

@end

To use:

#import "FlixHelpers.h"

// ...

- (void)viewDidLoad {
    //...

    [FlixHelpers fetchMovies];
}

This also helps in line with creating the separation of model-view-controller, where the data from the movies is essentially the model.

Nits

nits == tiny things that don't hurt anything, but are nice for legibility

Comments

@ FB, we don't want to leave behind commented out code; comments are strictly used to explain what's going on. So, for example, this would be cleaned up before being pushed to the FB codebase:

// //Ends refreshing regardless of whether there was an error with the network or not.
// [self.refreshControl endRefreshing];
// //Stops animating loading indicator.
// [self.networkIndicator stopAnimating];

I also noticed TODOs for code that you actually implemented lol - you can probably remove the comment completely and/or the TODO so it isn't confusing to the reader.

Indentation

Not sure if this is actually XCode doing the wonky indentation, but if not, you can fix it by highlighting -> CTRL-I

success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *smallImage) {
// smallImageResponse will be nil if the smallImage is already available
// in cache (might want to do something smarter in that case).
weakCell.posterView.alpha = 0.0;
weakCell.posterView.image = smallImage;
[UIView animateWithDuration:0.3

Coding Standards

This is the TINIEST nit because tbh these are probably tiny typos, but going to mention it anyways to be reflective of FB coding standards, but for spacing, it's best to err on the side of how CodePath has been doing them:

-(void) searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {

Better:

- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
    // ...
}

//If no search, don't filter anything

Better:

// If no search, don't filter anything

UICollectionViewFlowLayout *layout = (UICollectionViewFlowLayout *) self.collectionView.collectionViewLayout;

Better:

UICollectionViewFlowLayout *layout = (UICollectionViewFlowLayout *)self.collectionView.collectionViewLayout;

Other / Good-to-Know

[self presentViewController:alert animated:YES completion:^{
// optional code for what happens after the alert controller has finished presenting
}];

completion: can be nil

[self presentViewController:alert animated:YES completion:nil];

Project Feedback!

Nice work! The purpose of this project was to continue learning Objective-C and the Cocoa Touch (iOS) framework. You should be comfortable creating table views (one of the most common views in iOS) and working with array of dictionaries created from JSON (in this case from the Movies Database API).

A key part of these projects is that you work to polish the visuals and the small UI / UX touches. Developing your design sense is an important part of being a mobile engineer. You'll find that perfecting the UI / UX will often lead to interesting technical challenges as well because the libraries may not behave exactly as you want them to, so you'll have to learn how to achieve the effect that you want. A few other things to note:

  • Did you use groups to organize your source files? It's pretty common to organize your source files into Groups, especially for larger projects. You can organize by type of class (i.e. View Controllers, Views, etc) or for larger apps by functionality (i.e. Home Screen, Search Screen, etc).
  • Did you minimize the number of public methods and properties in your classes? You should always try to minimize the number of properties and methods that are in the header files. Only expose what you have to, e.g., properties and methods that must be accessed by other classes.
  • Did you properly set the Content Mode for your ImageViews? By default the UIContentMode will stretch the image to match the dimensions of the image view, which is probably not what you want. The most common combination is to use Aspect Fill combined with clipping subviews.

However there were some user stories not reflected on your GIF:

  • User can pull to refresh the movie list.
  • User sees an error message when there's a networking error.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.