Whats the Swift animate WithDuration syntax?

Swift 3/4 Syntax Here’s an update with the Swift 3 Syntax: UIView.animate(withDuration: 0.5, delay: 0.3, options: [.repeat, .curveEaseOut, .autoreverse], animations: { self.username.center.x += self.view.bounds.width }, completion: nil) If you need to add a completion handler just add a closure like so: UIView.animate(withDuration: 0.5, delay: 0.3, options: [.repeat, .curveEaseOut, .autoreverse], animations: { // animation stuff }, … Read more

How to Read Plist without using NSDictionary in Swift?

The native Swift way is to use PropertyListSerialization if let url = Bundle.main.url(forResource:”Config”, withExtension: “plist”) { do { let data = try Data(contentsOf:url) let swiftDictionary = try PropertyListSerialization.propertyList(from: data, format: nil) as! [String:Any] // do something with the dictionary } catch { print(error) } } You can also use NSDictionary(contentsOf: with a type cast: if … Read more

AVAudioEngine downsample issue

An other way to do it , with AVAudioConverter in Swift 5 let engine = AVAudioEngine() func setup() { let input = engine.inputNode let bus = 0 let inputFormat = input.outputFormat(forBus: bus ) guard let outputFormat = AVAudioFormat(commonFormat: .pcmFormatFloat32, sampleRate: 8000, channels: 1, interleaved: true), let converter = AVAudioConverter(from: inputFormat, to: outputFormat) else{ return } … Read more

Converting from Swift string to const char*

You should be able to pass a String directly to a C function expecting const char * and it will be automatically converted to a null-terminated UTF-8 string: let string = “string” let node = artnet_new(string, 1) See Interacting with C APIs for more information. Here is the relevant excerpt: When a function is declared … Read more