Code Monkey home page Code Monkey logo

pokemondex's Introduction

PokemonDex

pokemondex's People

Contributors

nillias avatar

Stargazers

Sarah Madalena avatar Pedro Muniz avatar Paulo Henrique avatar Luiz Sena avatar

Watchers

 avatar

Forkers

luizerz

pokemondex's Issues

Code Review

Desacoplamento

Primeiramente, parabéns pelo desempenho que tu teve Nillia, apesar de parecer simples eu sei que você teve muito trabalho!

Na linha de código seguinte, presente no arquivo API.swift, temos que o trecho de código que deveria está em um arquivo separado (model) se encontra dentro de outro.

struct Data: Codable {
let data: [Card]
}
struct Card: Codable {
let id, name: String
let images: Images
}
struct Images: Codable {
let large: String
}

Para desacoplar essa sequencia de código devemos criar um novo arquivo .swift, basta apertar "cmd + n", escolher a opção swift file e nomear como uma model (ex: DataModel).

Outro arquivo que necessita de um desacoplamento é o ViewController.swift, esse é bem mais rápido já que você não precisará que criar um novo arquivo. Tendo o seguinte trecho de código:

class ViewController: UIViewController, UISearchResultsUpdating {
    
    //busca da search bar
    func updateSearchResults(for searchController: UISearchController) {
        guard let text = searchController.searchBar.text else {
            return
        }
        
        print(text)
    }

Podemos desacoplar o protocolo UISearchResultsUpdating utilizando um extension e trazendo a func dele para dentro desse extension

CodeExemple do review anterior:

extension ViewController: UISearchResultsUpdating {
 func updateSearchResults(for searchController: UISearchController) {
        guard let text = searchController.searchBar.text else {
            return
        }
}

Trabalhando nos apontamentos feitos, seu código se tornará mais legível, desacoplado, e padronizado. Voltando a inteirar parabéns por ter indo em frente com o projeto e não desistido 💯

Olá Nillia, seu projeto ficou bem legal, dá para notar que você se empenhou nele!

Percebi que você deixou todas as funções dos métodos da sua ViewController em apenas um lugar. Da seguinte forma:

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return dataSave.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! CardUICell
cell.configFromCoreData(with: dataSave[indexPath.row])
cell.removeButton()
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
print(dataSave[indexPath.row].url ?? "")
}

Ficaria melhor organizado, bem como maia fácil de ler, se você fizesse uma extensão da sua classe para método.

Aqui um exemplo de como ficariam as extensões com seus respectivos métodos e func:

extension CardSaveViewController: UITableViewDataSource {
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
            return dataSave.count
        }
        
        func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
            let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! CardUICell
           
            cell.configFromCoreData(with: dataSave[indexPath.row])
            cell.removeButton()
            return cell
        }
}

extension CardSaveViewController: UITableViewDelegate {
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath, animated: true)
        print(dataSave[indexPath.row].url ?? "")
        
    }
}

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.