krzyzanowskim / Natalie

Natalie - Storyboard Code Generator (for Swift)
http://blog.krzyzanowskim.com/2015/04/15/natalie-storyboard-code-generator/
MIT License
1.17k stars 74 forks source link

using a switch statement in prepareForSegue #76

Closed ollieatkinson closed 8 years ago

ollieatkinson commented 8 years ago

Im interested to know what is actually broken here, what is it that you are trying to achieve?

Here is a playground I was messing about in, could you please give me one in a broken state?

enum Segue: String {
  case ScreenOneSegue = "abcdef"
}

func prepareForSegue(storyboardSegue: UIStoryboardSegue, sender: AnyObject?) {

//  if storyboardSegue == Segue.ScreenOneSegue {
//    let viewController = storyboardSegue.destinationViewController
//    viewController?.view.backgroundColor = UIColor.yellowColor()
//  }

  guard let identifier = storyboardSegue.identifier, segue = Segue(rawValue: identifier) else {
    return
  }

  switch segue {

  case .ScreenOneSegue:
    print("got here")

  }

  switch storyboardSegue {

  case _ where storyboardSegue == Segue.ScreenOneSegue:
    print("got here")

  default:
    break

  }

}

func ==<T: RawRepresentable where T.RawValue == String>(x: UIStoryboardSegue, y: T) -> Bool {
  return x.identifier == y.rawValue
}

From what I can gather you are trying to remove the need for

guard let identifier = storyboardSegue.identifier, segue = Segue(rawValue: identifier) else {
  return
}

and perform a switch on the UIStoryboardSegue itself

krzyzanowskim commented 8 years ago

would you please be more specific ? if there is error with Natalie, please point me to what is the nature and where.

ollieatkinson commented 8 years ago

In your README you have the following:

image

linking to this

I created an issue so we can remove it

krzyzanowskim commented 8 years ago

ah, so it's fixed now?

ollieatkinson commented 8 years ago

I am questioning the motive around the statement in the first place, I am only second guessing your reasoning for the comment in the read me.

I can understand what you might of being trying to do but if you could clarify what you want to do in the switch statement?

krzyzanowskim commented 8 years ago

the switch statement? is something fundamentally wrong with the switch statement? sorry I'm a bit confused. Is this, by any chance, academic discussion if vs. switch? 😂.

You can use what ever works better for you. Working switch would be great, though. When it comes to "what's broken" then... I don't know, it's Swift limitation.

ollieatkinson commented 8 years ago

Sorry if I'm not being clear enough.

I do not understand why we have the comment in the README if its down to an implementation detail of how to use the statement.

Ill close this then but we probably need to remove that from the README as its mis-leading

krzyzanowskim commented 8 years ago

yeap. It's side note there. It "should" work, and will probably some day ;)