Giter Club home page Giter Club logo

bitcoin-swift-ios's Introduction

Bit Coin

Aplicação consumindo api BitCoin

Motivação

Praticar o uso do desing patern delegate e MVC

Feature

  • Maneira de transformar os dados retornando da api em strings e usar objeto String
  • Para implementar desing patern delegataion usei operador optional assim ele não ira obrigar ser inserido no construtor do struct
  • Aprendi o uso do imageViewPicker
  • Ele utiliza o delegate UIPickerViewDelegate para acessar os campos do picker view
  • E o UIPickerViewDataSource para preencher os campos do picker view
  • Vantagem de usar o desing partern delegation e compartilhar métodos ou propriedades sem precisar instanciar e reduzimos código
  • Abaixo didUpdateBitCoin e didFailWithError possuem o suficiente para view countroler exibir os dados casso sucesso ou error, sem precisar repetir ou instanciar o delegate
  • Preciso apenas o uso do self
//transformar os dados em string,tabem e bom para testar
//se deu sucesso a request
//let dataString = String(data: safeData,encoding: .utf8)


//bitCoinManager

var delegateBitCoin: BitCoinDelegate?
if let bitcoinData = jsonParse(safeData) {
	 delegateBitCoin?.didUpdateBitCoin(bitcoinData)
}

if error != nil {
	 delegateBitCoin?.didFailWithError(error!)
		return
}



//======================== 
// quem criou a logica de negocio foi na struct bitCoinManager
//bitCoinManager.delegateBitCoin = self
//Delegate

extension ViewController:BitCoinDelegate {
	func didUpdateBitCoin(_ bitcoin: BitCoinModel) {
		DispatchQueue.main.async {
			self.countryBitCoin.text = bitcoin.country
			self.valueCurrentBitCoin.text = String(format: "%.2f",  bitcoin.rate)
		}
		
	}
	
	func didFailWithError(_ error: Error) {
		print(error)
	}
	
}


//====================
//uipicker view

extension ViewController:UIPickerViewDataSource {
	
	//quantidade de colunas
	func numberOfComponents(in pickerView: UIPickerView) -> Int {
		return 1
	}
	
	//quantidade de linhas
	func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
		return bitCoinModel.countryBitCoin.count
	}
	
}

extension ViewController:UIPickerViewDelegate {
	
	//acessando o indice do valor selecionado no picker view
	func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
		bitCoinModel.geIndexCountry(row)
	}
	
	//preenchendo os dados
	func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
		return bitCoinModel.countryBitCoin[row]
	}
}


Screen

screen

bitcoin-swift-ios's People

Contributors

kenjimaeda54 avatar

Watchers

 avatar

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.