In Swift, can you split a string by another string, not just a character?
import Foundation let inputString = “This123Is123A123Test” let splits = inputString.components(separatedBy: “123”)
import Foundation let inputString = “This123Is123A123Test” let splits = inputString.components(separatedBy: “123”)
As I have worked on both iOS & Android, You need to play with constraint outlet in ios to achieve Android functioning. iOS Does not support automatically like Android native support on visibility GONE & VISIBLE You need to hook the outlet of particular constraint(it may vertical/horizontal/height) you need to set it to 0 & … Read more
I figured it out but Apple didn’t make it so obvious. The callback function from the delegate AVCaptureMetadataOutputObjectsDelegate has been renamed and the parameter names are different! So, replace func captureOutput(_ captureOutput: AVCaptureOutput!, didOutputMetadataObjects metadataObjects: [Any]!, from connection: AVCaptureConnection!) to func metadataOutput(_ output: AVCaptureMetadataOutput, didOutput metadataObjects: [AVMetadataObject], from connection: AVCaptureConnection) My view controller is now … Read more
Ollie’s answer is definitely the best way to go for this case, but it does push some knowledge into the caller, which may be undesirable. It also isn’t very flexible. I still think it’s a great answer and exactly what you want here, but this is a nice simple example to explore custom structural encoding. … Read more
There’s a subtle, but important difference between these two lines of code: // Exhibit 1 foo = try container.decode(Int?.self, forKey: .foo) // Exhibit 2 foo = try container.decodeIfPresent(Int.self, forKey: .foo) Exhibit 1 will parse: { “foo”: null, “bar”: “something” } but not: { “bar”: “something” } while exhibit 2 will happily parse both. So in … Read more
Swift 4 introduced a family of concrete Key-Path types, a new Key-Path Expression to produce them and a new closure-based observe function available to classes that inherit NSObject. Using this new set of features, your particular example can now be expressed much more succinctly: self.observation = object.observe(\.keyPath) { [unowned self] object, change in self.someFunction() } … Read more
The error is telling you that as of iOS 12 the old UIImageJPEGRepresentation function has been replaced with the new jpegData method on UIImage. Change: let imageData = UIImageJPEGRepresentation(image, 0.75) to: let imageData = image.jpegData(compressionQuality: 0.75) Similarly, the use of UIImagePNGRepresentation has been replaced with pngData().
Well as the other guys also explained that braces are a must in swift. But for simplicity one can always do something like: let a = -5 // if the condition is true then doThis() gets called else doThat() gets called a >= 0 ? doThis(): doThat() func doThis() { println(“Do This”) } func doThat() … Read more
In Swift 3 you can omit the associated value of type Void: let res: Result<Void> = .success() In Swift 4 you have to pass an associated value of type Void: let res: Result<Void> = .success(()) // Or just: let res = Result.success(())
I think this ‘bug’ may be a Swift 4 “feature”, specifically something they call “Exclusive access to Memory”. Check out this WWDC video. Around the 50-minute mark, the long-haired speaker explains it. https://developer.apple.com/videos/play/wwdc2017/402/?time=233 You could try turning the thread sanitizer off in your scheme settings if you’re happy to ignore it. However, the debugger is … Read more