Create steemit account upvote recharge time calculator ios app.
utopian-io·@iamankit·
0.000 HBDCreate steemit account upvote recharge time calculator ios app.
 #### What Will I Learn? - You will learn making app in xcode - You will learn how to write mathematical equations in Swift. - You will learn how to convert string value to second, minutes, hours. #### Requirements - Xcode - Basic Understanding of Xcode. - Understanding of swift language in iOS development #### Difficulty - Basic #### Tutorial Contents Today in this tutorial we will learn how to create a app that tells how much time your voting power takes to recharge back to 100%. After following this tutorial to end you have an app in which you can enter your current voting power and the app tells you how much time your account needs to regain 100% voting power. So let's start creating this beautiful app.  - First of all create a single view app in your Xcode. - Then open story board and put two textfields and one button on your view controller. Something like this -  - Now make outlets of textfields and button in your viewController file, so that we access them with in our code. Make outlets like this :- <pre> <code> import UIKit class ViewController: UIViewController { @IBOutlet var targetedVotingPowerTextFieldValue: UITextField! @IBOutlet var currentVotingPowerTextFieldValue: UITextField! override func viewDidLoad() { super.viewDidLoad() self.targetedVotingPowerTextFieldValue.keyboardType = .numberPad self.currentVotingPowerTextFieldValue.keyboardType = .numberPad } @IBAction func calculateButtonClick(_ sender: Any) { //we will write code here to calculate time later } } </code> </pre> <li> Now we need to fetch the textfield values on click of calculate but so that we can calculate time from those values. To calculate time from values we need to write the following code in our "calculate button clicked" outlet. Like this -:</li> <pre> <code> @IBAction func calculateButtonClick(_ sender: Any) { let targetedValue = Int(self.targetedVotingPowerTextFieldValue.text!) let currentValue = Int(self.currentVotingPowerTextFieldValue.text!) let difference = (targetedValue! - currentValue!) var timeInSecond = Double(difference) * 43.2 / 0.01 } </code> </pre> <li>Now we need to show the calculate time to user. For this drag 4 labels under button on your viewController in storyboard like this :- </li> https://res.cloudinary.com/hpiynhbhq/image/upload/v1518956965/v4luxjcdhubmdqce3sdr.png We will update those labels text from our code. So to access labels from code, first make their outlets in viewController file. <pre> <code> class ViewController: UIViewController { @IBOutlet var targetedVotingPowerTextFieldValue: UITextField! @IBOutlet var currentVotingPowerTextFieldValue: UITextField! @IBOutlet var secondsLabel: UILabel! //outlet of the label1 @IBOutlet var minutesLabel: UILabel! //outlet of the label2 @IBOutlet var hoursLabel: UILabel! //outlet of the label3 @IBOutlet var daysLabel: UILabel! //outlet of the label4 override func viewDidLoad() { super.viewDidLoad() self.targetedVotingPowerTextFieldValue.keyboardType = .numberPad self.currentVotingPowerTextFieldValue.keyboardType = .numberPad } @IBAction func calculateButtonClick(_ sender: Any) { let targetedValue = Int(self.targetedVotingPowerTextFieldValue.text!) let currentValue = Int(self.currentVotingPowerTextFieldValue.text!) let difference = (targetedValue! - currentValue!) var timeInSecond = Double(difference) * 43.2 / 0.01 } } </code> </pre> <li>After making outlets of labels we need to show the time on click of calculate button. To update labels text we will call a function when calculate button clicked. So make changes in your code like this - </li> <pre> <code> @IBAction func calculateButtonClick(_ sender: Any) { let targetedValue = Int(self.targetedVotingPowerTextFieldValue.text!) let currentValue = Int(self.currentVotingPowerTextFieldValue.text!) let difference = (targetedValue! - currentValue!) var timeInSecond = Double(difference) * 43.2 / 0.01 self.updateLabels(time: Int(timeInSecond), targetedValue: targetedValue!) } func updateLabels(time: Int, targetedValue: Int) { let minutes = time / 60 let hours = minutes / 60 let days = hours / 24 self.secondsLabel.text = "In order to reach the percentage of " + "\(targetedValue)%" + " you have to wait " + "\(time) seconds" self.minutesLabel.text = "In order to reach the percentage of " + "\(targetedValue)%" + " you have to wait " + "\(minutes) minutes" self.hoursLabel.text = "In order to reach the percentage of " + "\(targetedValue)%" + " you have to wait " + "\(hours) hours" self.daysLabel.text = "In order to reach the percentage of " + "\(targetedValue)%" + " you have to wait " + "\(days) days" } </code> </pre> <li>Ok now run your app in simulator and test the app by calculating your voting power time. I am sure everything will be running file, if you follow the tutorial perfectly. Enjoy coding guys. In next tutorial we will make another steemit tool in our xcode.</li> #### Till then stay well and code well. #### Thanks <br /><hr/><em>Posted on <a href="https://utopian.io/utopian-io/@iamankit/create-steemit-account-upvote-recharge-time-calculator-ios-app">Utopian.io - Rewarding Open Source Contributors</a></em><hr/>