Post

Replies

Boosts

Views

Activity

Why am I getting "Expressions are not allowed at the top level" error?
var millisecondsSince1970: Int64 {     Int64((self.timeIntervalSince1970 * 1000.0).rounded())   }       init(milliseconds: Int64) {     self = Date(timeIntervalSince1970: TimeInterval(milliseconds) / 1000)   } } // Today in milliseconds Date().millisecondsSince1970 // 1641554695757 // The Date for 1 000 000 000 000 milliseconds print(Date(milliseconds: 1_000_000_000_000)) // 2001-09-09 01:46:40 +0000
1
0
745
Jun ’22
I am trying to log touch coordinates into the CSV file, but I am getting "No exact matches in call to initializer" error
I am trying to log touch coordinates into the CSV file, but I am getting "No exact matches in call to initializer" error. I need to parse the touch coordinates as String. What is going wrong here?   super.touchesBegan(touches , with: event)     let touch = touches.first!     let location = touch.location(in: view) //Returns the current location of the receiver in the coordinate system.     let mylocation = String(location) ***No exact matches in call to initializer        //    print("touches began \(location)")           let fileName2 = "testing2.csv" // CSV filename           let documentDirectoryPath2 = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] as String           let documentURL2 = URL(fileURLWithPath: documentDirectoryPath2).appendingPathComponent(fileName2)           let output2 = OutputStream.toMemory() // stream data into memory     let csvWriter2 = CHCSVWriter(outputStream: output2,                   encoding: String.Encoding.utf8.rawValue, delimiter: unichar(",".utf8.first!))           csvWriter2?.writeField("Timestamp")     csvWriter2?.writeField("Timestamp in miliseconds")     csvWriter2?.finishLine()           //Array to add data       var arrOfTimestamp = [[String]]()   //    var arrOfTimeInMiliSec = [[Int]]()              arrOfTimestamp.append([mylocation])   //    arrOfTimeInMiliSec.append([time])       for(elements) in arrOfTimestamp.enumerated() {         csvWriter2?.writeField(elements.element[0])       }       csvWriter2?.closeStream()       let buffer = (output2.property(forKey: .dataWrittenToMemoryStreamKey) as? Data)!       do{         try buffer.write(to: documentURL2)       }       catch {       }
1
0
625
Jun ’22