wickwirew / Runtime

A Swift Runtime library for viewing type info, and the dynamic getting and setting of properties.
MIT License
1.08k stars 94 forks source link

Calling a function after using `createInstance()` #82

Open derLalla opened 3 years ago

derLalla commented 3 years ago

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?