29 lines
		
	
	
		
			944 B
		
	
	
	
		
			Swift
		
	
	
			
		
		
	
	
			29 lines
		
	
	
		
			944 B
		
	
	
	
		
			Swift
		
	
	
| // IState.swift
 | |
| // The interface for implementing states in a StateMachine
 | |
| // Ported from Android implementation
 | |
| 
 | |
| import Foundation
 | |
| 
 | |
| /// Protocol defining the interface for implementing states in a state machine
 | |
| public protocol IState {
 | |
|     
 | |
|     /// Called when a state is entered
 | |
|     /// - Parameters:
 | |
|     ///   - from: State we are coming from
 | |
|     ///   - params: Optional parameters for state transition
 | |
|     func enter(from: IState?, params: Any?)
 | |
|     
 | |
|     /// Called when a state is exited
 | |
|     /// - Parameter to: State we are transitioning to
 | |
|     func exit(to: IState?)
 | |
|     
 | |
|     /// Process a message sent to the state machine
 | |
|     /// - Parameter msg: The message to process
 | |
|     /// - Returns: HANDLED if processing has completed or NOT_HANDLED if the message wasn't processed
 | |
|     func processMessage(_ msg: Message) -> Bool
 | |
|     
 | |
|     /// Name of State for debugging purposes
 | |
|     /// - Returns: name of state
 | |
|     var name: String { get }
 | |
| }
 |