Home iOS Enums, Classes and Buttons, Methods
Reply: 1

iOS Enums, Classes and Buttons, Methods

Ty-wan Claxton
1#
Ty-wan Claxton Published in 2018-01-13 01:11:12Z

So I have a few questions in general about tying things together. Lets say I have an enum filled with conditions as shown below.

enum Condition {

  case poor 
  case fair 
  case excellent
  case dan

}

I also have a class with stored properties

class Shoe {
  var color: Condition
  var laces: Condition

  init(color: Condition, laces: Condition) {
    self.color = color
    self.laces = laces
  }
}

My goal is to have users decide the condition of the object/variable inside of the class. Ideally I would like to accomplish this using MVC, setting the conditions up as buttons via UI. I'm learning online So I have a few questions.

  1. For the enum, is their anyway to connect buttons created in UI to the view controller in a way that the buttons represent the enum cases.
  2. For the class, although I'm not sure If its the best idea, Im thinking of creating a method that takes a dictionary of type [Object/Variable: Condition] and returns an interpolated string. "(object) is in (condition) Condition"
  3. I am also thinking I should create a second helper method to save the information and a for in loop to loop through the variables in the class ( there will be more variables than below).
  4. The final question I have is if its possible to have an label represent the stored properties in a class and how I should approach the label switching on variables in the class?
Joe Wick
2#
Joe Wick Reply to 2018-01-13 04:44:41Z

In the order you asked:

  1. Learn about creating outlets for your UI objects. These enable you to call a function when your button is pushed, and therefore are a useful connection between UI and your variables. You can also use them to create a variable in your code that represents a UI object, allowing you to edit the properties as your app runs.

  2. I’m not entirely sure how you want your app to behave, but that would work if you wanted to return the condition of all objects as a string

  3. Again it depends on what you want your app to do

  4. My understanding is that you want a label that displays the values of class variables. In order to do that, you’ll want to create an outlet for the label in your ViewController and use the .text property of the label to display values

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.34281 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO