How to Make a Basic Finite State Machine in Objective-C

后端 未结 5 2005
长发绾君心
长发绾君心 2020-12-07 17:45

I am attempting to build an FSM to control a timer in (iphone sdk) objective c. I felt it was a necessary step, because I was otherwise ending up with nasty spaghetti code c

5条回答
  •  有刺的猬
    2020-12-07 18:19

    I am rather new at Objective-C, but I would suggest that you look at straight ANSI C implementation for the State Machine.

    Just because you're using Cocoa doesn't mean you have to use Objective-C messages here.

    In ANSI C, a state machine implementation can be very straightforward and readable.

    My last implementation in C of a FSM specified #define STATE_x or enumerate types for the states and had a table of pointers to functions to execute each state.

提交回复
热议问题