import Foundation

protocol HasWhy
{
  var why : Int { get }
}

protocol ClassHasWhy : class
{
  var why : Int { get }
}

class ShouldBeWhy : NSObject, ClassHasWhy, HasWhy
{
  var before_why : Int = 0xfeedface
  var why : Int = 10
  var after_why : Int = 0xdeadbeef
}

class ClassByWhy<T> where T : ClassHasWhy 
{
  let myWhy : Int
  init(input : T)
  {
    myWhy = input.why  // Break here and print input
  }
}

class ByWhy<T> where T : HasWhy 
{
  let myWhy : Int
  init(input : T)
  {
    myWhy = input.why  // Break here and print input
  }
}

func doIt() 
{
  let mySBW = ShouldBeWhy()
  let byWhy = ByWhy(input: mySBW)
  let classByWhy = ClassByWhy(input: mySBW)
  print(byWhy.myWhy, classByWhy.myWhy)
}

doIt()
import Foundation

protocol HasWhy : class
{
  var why : Int { get }
}

class ShouldBeWhy : NSObject, HasWhy
{
  var why : Int = 10
}

class ByWhy<T> where T : HasWhy 
{
  let myWhy : Int
  init(input : T)
  {
    myWhy = input.why  // Break here and print input
  }
}

func doIt() 
{
  let mySBW = ShouldBeWhy()
  let myByWhy = ByWhy(input: mySBW)
  print(myByWhy.myWhy)
}

doIt()
--- 
+++ 
@@ -1,13 +1,29 @@
 import Foundation
 
-protocol HasWhy : class
+protocol HasWhy
 {
   var why : Int { get }
 }
 
-class ShouldBeWhy : NSObject, HasWhy
+protocol ClassHasWhy : class
 {
+  var why : Int { get }
+}
+
+class ShouldBeWhy : NSObject, ClassHasWhy, HasWhy
+{
+  var before_why : Int = 0xfeedface
   var why : Int = 10
+  var after_why : Int = 0xdeadbeef
+}
+
+class ClassByWhy<T> where T : ClassHasWhy 
+{
+  let myWhy : Int
+  init(input : T)
+  {
+    myWhy = input.why  // Break here and print input
+  }
 }
 
 class ByWhy<T> where T : HasWhy 
@@ -22,8 +38,9 @@
 func doIt() 
 {
   let mySBW = ShouldBeWhy()
-  let myByWhy = ByWhy(input: mySBW)
-  print(myByWhy.myWhy)
+  let byWhy = ByWhy(input: mySBW)
+  let classByWhy = ClassByWhy(input: mySBW)
+  print(byWhy.myWhy, classByWhy.myWhy)
 }
 
 doIt()
Add an example that doesn't fail, and differs only in the
class attribute to the protocol.
