Skip to content

Calling a function after using createInstance() #82

@derLalla

Description

@derLalla

Hey, is it possible to call a function (e.g. via String) of a class which is created by using createInstance()?

I am creating test cases for Classes and check if a function was implemented correctly.
The idea is, that I provide an empty class, e.g. "Student" and a UML diagram which states that a Student has a function named "getStudentId()". A student now needs to implement the code.
Now I want to write a test case which tries to initialize the "Student" class and
1.) check if the function "getStudentId()" exists and
2.) check if it returns the correct value

I can check with

if let inferredClass = NSClassFromString("Student") {
...
} else {
  print("no class found")
  XCTFail("Student.swift is not implemented!")
}

that the class exists, but I cannot call the function.
Do you have an idea?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions