lundi 3 juillet 2023

How do I implement business rules within a Swift/iOS class so that rules&decisions can be made based on a core data table and not hardcoded in code?

I have the following types of variables within swift code and would like to take specific action based on a rules based table. For example:

Class Variables

joints.shoulder.left.y
joints.arm.wrist.left.y

Typical swift/pseudo code:

if (joints.arm.wrist.left.y > joints.shoulder.left.y){
   print("warning")
   self.elevated = true }

Problem: Instead of coding if/then statements, I'd like to maintain this logic in a table which contains the following columns

  1. Left expression (e.g. joints.arm.wrist.left.y)
  2. Condition (e.g. > )
  3. Right expression (e.g. joints.shoulder.left.y)
  4. Results (e.g. self.elevated = true)

I'd like to know what is the best way to be able to evaluate the expressions held in the table, but then to set the actual variable within the class to be self.elevated = true. Basically I need to figure out a way in Swift/iOS to not only to evaluate the expressions, but also to take the string "self.elevated" and to use that string literally as it refers to the variable within the class itself.

Thank you.

Aucun commentaire:

Enregistrer un commentaire