Skip to content

Instantly share code, notes, and snippets.

@Ben-G
Last active May 5, 2025 13:33

Revisions

  1. Ben-G revised this gist Jun 14, 2015. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions DynamicInit.swift
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,7 @@
    protocol Initializable {
    init()
    }

    class A : Initializable {
    var content:String

  2. Ben-G renamed this gist May 30, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. Ben-G created this gist Feb 28, 2015.
    13 changes: 13 additions & 0 deletions DynamicInit
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    class A : Initializable {
    var content:String

    required init() {
    content = "TestContent"
    }
    }

    func createInstance<T where T:Initializable>(typeThing:T.Type) -> T {
    return typeThing()
    }

    let a = createInstance(A)