Skip to content

Instantly share code, notes, and snippets.

@furkankadioglu
Created August 20, 2017 12:54
Show Gist options
  • Save furkankadioglu/230de9db88ef91fb3e8818a7d1ea550e to your computer and use it in GitHub Desktop.
Save furkankadioglu/230de9db88ef91fb3e8818a7d1ea550e to your computer and use it in GitHub Desktop.
Provider Mutating Hatası
//
// Provider.swift
// Sanal Piyasa
//
// Created by Furkan KADIOGLU on 28/06/2017.
// Copyright © 2017 Furkan KADIOGLU. All rights reserved.
//
import UIKit
import Alamofire
import SwiftyJSON
import Foundation
struct Provider {
var url:String
var name:String
var identifier:String
var currency:Currency
var arrayIdentifier:String = ""
var tryPrice:Double = 0.0
var usdPrice:Double = 0.0
init(url:String, name:String, identifier:String, currency:Currency, arrayIdentifier:String, tryPrice:Double = 0.0, usdPrice:Double = 0.0)
{
self.url = url
self.name = name
self.identifier = identifier
self.currency = currency
}
mutating func updateProcess(tryLabel: UILabel, usdLabel: UILabel, url: String, identifier: String, currency: Currency, arrayIdentifier:String = "")
{
Alamofire.request(url).responseJSON { response in
if let json = response.result.value
{
let data = JSON(json)
var ask : Double = 0
if(self.name == "Coindesk")
{
ask = data["bpi"]["USD"]["rate_float"].doubleValue
}
else
{
if(arrayIdentifier != "")
{
ask = data[arrayIdentifier][identifier].doubleValue
}
else
{
ask = data[identifier].doubleValue
}
}
if(currency.name == "USD")
{
usdLabel.text = "\(Int(ask)) $"
ask = ask * (currency1.value! * 1.03)
tryLabel.text = "\(Int(ask)) TL"
}
else if(currency.name == "TRY")
{
tryLabel.text = "\(Int(ask)) TL"
ask = ask / currency1.value!
usdLabel.text = "\(Int(ask)) $"
}
}
else
{
usdLabel.text = "Error!"
tryLabel.text = "Error!"
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment