@@ -114,7 +114,7 @@ import Foundation
114114 }
115115
116116 /// The local index mirroring this remote index (lazy instantiated, only if mirroring is activated).
117- lazy var localIndex : ASLocalIndex ! = ASLocalIndex ( dataDir: self . offlineClient. rootDataDir, appID: self . client. appID, indexName: self . name)
117+ lazy var localIndex : ASLocalIndex = ASLocalIndex ( dataDir: self . offlineClient. rootDataDir, appID: self . client. appID, indexName: self . name)
118118
119119 /// The mirrored index settings.
120120 let mirrorSettings = MirrorSettings ( )
@@ -178,20 +178,20 @@ import Foundation
178178 private var syncing : Bool = false
179179
180180 /// Path to the temporary directory for the current sync.
181- private var tmpDir : String !
181+ private var tmpDir : String ?
182182
183183 /// The path to the settings file.
184- private var settingsFilePath : String !
184+ private var settingsFilePath : String ?
185185
186186 /// Paths to object files/
187- private var objectsFilePaths : [ String ] !
187+ private var objectsFilePaths : [ String ] ?
188188
189189 /// The current object file index. Object files are named `${i}.json`, where `i` is automatically incremented.
190190 private var objectFileIndex = 0
191191
192192 /// The operation to build the index.
193193 /// NOTE: We need to store it because its dependencies are modified dynamically.
194- private var buildIndexOperation : Operation !
194+ private var buildIndexOperation : Operation ?
195195
196196 /// Path to the persistent mirror settings.
197197 private var mirrorSettingsFilePath : String {
@@ -306,9 +306,9 @@ import Foundation
306306 // Create temporary directory.
307307 do {
308308 tmpDir = URL ( fileURLWithPath: NSTemporaryDirectory ( ) ) . appendingPathComponent ( " algolia " ) . appendingPathComponent ( UUID ( ) . uuidString) . path
309- try FileManager . default. createDirectory ( atPath: tmpDir, withIntermediateDirectories: true , attributes: nil )
309+ try FileManager . default. createDirectory ( atPath: tmpDir! , withIntermediateDirectories: true , attributes: nil )
310310 } catch _ {
311- NSLog ( " ERROR: Could not create temporary directory '%@' " , tmpDir)
311+ NSLog ( " ERROR: Could not create temporary directory '%@' " , tmpDir! )
312312 }
313313
314314 // NOTE: We use `NSOperation`s to handle dependencies between tasks.
@@ -326,8 +326,8 @@ import Foundation
326326 assert ( json != nil )
327327 // Write results to disk.
328328 let data = try JSONSerialization . data ( withJSONObject: json!, options: [ ] )
329- self . settingsFilePath = URL ( fileURLWithPath: self . tmpDir) . appendingPathComponent ( " settings.json " ) . path
330- try data. write ( to: URL ( fileURLWithPath: self . settingsFilePath) , options: [ ] )
329+ self . settingsFilePath = URL ( fileURLWithPath: self . tmpDir! ) . appendingPathComponent ( " settings.json " ) . path
330+ try data. write ( to: URL ( fileURLWithPath: self . settingsFilePath! ) , options: [ ] )
331331 } catch let e {
332332 self . syncError = e
333333 }
@@ -338,7 +338,7 @@ import Foundation
338338 // Task: build the index using the downloaded files.
339339 buildIndexOperation = BlockOperation ( ) {
340340 if self . syncError == nil {
341- let status = self . localIndex. build ( fromSettingsFile: self . settingsFilePath, objectFiles: self . objectsFilePaths, clearIndex: true )
341+ let status = self . localIndex. build ( fromSettingsFile: self . settingsFilePath! , objectFiles: self . objectsFilePaths! , clearIndex: true )
342342 if status != 200 {
343343 self . syncError = HTTPError ( statusCode: Int ( status) )
344344 } else {
@@ -349,9 +349,9 @@ import Foundation
349349 }
350350 self . _syncFinished ( )
351351 }
352- buildIndexOperation. name = " Build \( self ) "
352+ buildIndexOperation! . name = " Build \( self ) "
353353 // Make sure this task is run after the settings task.
354- buildIndexOperation. addDependency ( settingsOperation)
354+ buildIndexOperation! . addDependency ( settingsOperation)
355355
356356 // Tasks: Perform data selection queries.
357357 objectFileIndex = 0
@@ -361,7 +361,7 @@ import Foundation
361361 }
362362
363363 // Finally add the build index operation to the queue, now that dependencies are set up.
364- offlineClient. buildQueue. addOperation ( buildIndexOperation)
364+ offlineClient. buildQueue. addOperation ( buildIndexOperation! )
365365 }
366366
367367 // Auxiliary function, called:
@@ -390,8 +390,8 @@ import Foundation
390390
391391 // Write results to disk.
392392 let data = try JSONSerialization . data ( withJSONObject: json!, options: [ ] )
393- let objectFilePath = URL ( fileURLWithPath: self . tmpDir) . appendingPathComponent ( " \( currentObjectFileIndex) .json " ) . path
394- self . objectsFilePaths. append ( objectFilePath)
393+ let objectFilePath = URL ( fileURLWithPath: self . tmpDir! ) . appendingPathComponent ( " \( currentObjectFileIndex) .json " ) . path
394+ self . objectsFilePaths! . append ( objectFilePath)
395395 try data. write ( to: URL ( fileURLWithPath: objectFilePath) , options: [ ] )
396396
397397 // Chain if needed.
@@ -404,7 +404,7 @@ import Foundation
404404 }
405405 }
406406 offlineClient. buildQueue. addOperation ( operation)
407- buildIndexOperation. addDependency ( operation)
407+ buildIndexOperation! . addDependency ( operation)
408408 }
409409
410410 /// Wrap-up method, to be called at the end of each sync, *whatever the result*.
@@ -416,7 +416,7 @@ import Foundation
416416
417417 // Clean-up.
418418 do {
419- try FileManager . default. removeItem ( atPath: tmpDir)
419+ try FileManager . default. removeItem ( atPath: tmpDir! )
420420 } catch _ {
421421 // Ignore error
422422 }
0 commit comments