How can I use String substring in Swift 4? ‘substring(to:)’ is deprecated: Please use String slicing subscript with a ‘partial range from’ operator

I have the following simple code written in Swift 3: let str = “Hello, playground” let index = str.index(of: “,”)! let newStr = str.substring(to: index) From Xcode 9 beta 5, I get the following warning: ‘substring(to:)‘ is deprecated: Please use String slicing subscript with a ‘partial range from’ operator. How can this slicing subscript with … Read more

How do I write dispatch_after GCD in Swift 3, 4, and 5?

In Swift 2, I was able to use dispatch_after to delay an action using grand central dispatch: var dispatchTime: dispatch_time_t = dispatch_time(DISPATCH_TIME_NOW, Int64(0.1 * Double(NSEC_PER_SEC))) dispatch_after(dispatchTime, dispatch_get_main_queue(), { // your function here }) But this no longer seems to compile since Swift 3. What is the preferred way to write this in modern Swift? 12 … Read more

The use of Swift 3 @objc inference in Swift 4 mode is deprecated?

Briefly, while using Xcode 9 Beta, I have run into the following warning: The use of Swift 3 @objc inference in Swift 4 mode is deprecated. Please address deprecated @objc inference warnings, test your code with “Use of deprecated Swift 3 @objc inference” logging enabled, and disable Swift 3 @objc inference.** After some research, I … Read more