@@ -170,40 +170,42 @@ private final actor NFCConnectionManager: NSObject {
170
170
private var _currentState = State . inactive
171
171
private var currentState : State {
172
172
get { _currentState }
173
- set { set ( state: newValue) }
173
+ set {
174
+ trace ( message: " State: \( currentState) → \( newValue) " )
175
+
176
+ defer { _currentState = newValue }
177
+
178
+ switch ( currentState, newValue) {
179
+
180
+ // Jump to 'connected'
181
+ case ( . inactive, let . connected( _, newTag) ) :
182
+ connection = connection ?? . init( )
183
+ didCloseConnection = nil
184
+ fallthrough
185
+ case ( . scanning, let . connected( _, newTag) ) :
186
+ didCloseConnection = . init( )
187
+ Task { await connection!. fulfill ( . init( tag: ISO7816Identifier ( newTag. identifier) ) ) }
188
+
189
+ // Jump to 'scanning'
190
+ case ( _, . scanning) :
191
+ connection = connection ?? . init( )
192
+ didCloseConnection = nil
193
+
194
+ // Jump to 'inactive'
195
+ case ( . connected, . inactive) :
196
+ fallthrough
197
+ case ( . scanning, . inactive) :
198
+ connection = nil
199
+ didCloseConnection = nil
200
+
201
+ default :
202
+ return
203
+ }
204
+ }
174
205
}
175
206
176
207
private func set( state newValue: State ) {
177
- trace ( message: " State: \( currentState) → \( newValue) " )
178
-
179
- defer { _currentState = newValue }
180
-
181
- switch ( currentState, newValue) {
182
-
183
- // Jump to 'connected'
184
- case ( . inactive, let . connected( _, newTag) ) :
185
- connection = connection ?? . init( )
186
- didCloseConnection = nil
187
- fallthrough
188
- case ( . scanning, let . connected( _, newTag) ) :
189
- didCloseConnection = . init( )
190
- Task { await connection!. fulfill ( . init( tag: ISO7816Identifier ( newTag. identifier) ) ) }
191
-
192
- // Jump to 'scanning'
193
- case ( _, . scanning) :
194
- connection = connection ?? . init( )
195
- didCloseConnection = nil
196
-
197
- // Jump to 'inactive'
198
- case ( . connected, . inactive) :
199
- fallthrough
200
- case ( . scanning, . inactive) :
201
- connection = nil
202
- didCloseConnection = nil
203
-
204
- default :
205
- return
206
- }
208
+ currentState = newValue
207
209
}
208
210
209
211
// @TraceScope
0 commit comments