I somehow miss what they want me to do when I want to cut a String in Swift. They told me Swift was "objective". But it rather is "not working". Removing a sub range from a string is explained in the docs (https://developer.apple.com/documentation/swift/string/3018537-removesubrange), which I read. But before I move back to ObjC, let me ask this question: From
measurements.removeSubrange(1..<4)
I made
logString = logString.removeSubrange(logSizeLimit..logString.count)
It said Cannot find operator '..' in scope; did you mean '...'?
I changed it to be ...
. It now tells me:
(1.) Cannot assign value of type '()' to type 'String'
(2.) Instance method 'removeSubrange' requires the types 'String.Index' and 'Int' be equivalent
This is my code:
public let logSizeLimit = 40960
public var logString = ""
func senderLoggedMessage(_ message:String) {
var msg = message + "\n"
msg += logString
logString = msg
if logString.count > logSizeLimit {
logString = logString.removeSubrange(logSizeLimit ... logString.count) // error line
}
}
Well. Does anyone know the answer?