Warning: Initialization of ‘UnsafeBufferPointer’ results in a dangling buffer pointer

I also met these annoying warnings. var str = “aaaaabbbbbccccc” var num1 = 1 var num2 = 22 var data = Data() // Initialization of ‘UnsafeBufferPointer<String>’ results in a dangling buffer pointer data.append(UnsafeBufferPointer(start: &str, count: 1)) // Initialization of ‘UnsafeBufferPointer<Int>’ results in a dangling buffer pointer data.append(UnsafeBufferPointer(start: &num1, count: 1)) // Initialization of ‘UnsafeBufferPointer<Int>’ results … Read more

Difference between switch cases “@unknown default” and “default” in Swift 5

From SE-0192: Handling Future Enum Cases (emphasis mine): When switching over a non-frozen enum, the switch statement that matches against it must include a catch-all case (usually default or an “ignore” _ pattern). switch excuse { case .eatenByPet: // … case .thoughtItWasDueNextWeek: // … } Failure to do so will produce a warning in Swift … Read more

Swift 5.1 Error: [plugin] AddInstanceForFactory: No factory registered for id

I believe you all might have added the AVFoundation to the frameworks list in Project General Info tab. Erroneous Code was as follows: import SwiftUI import AVFoundation struct PlayerDetailView: View { @State private var downloadedFilePath: URL = nil var audioPlayer: AVAudioPlayer var body: some View { And after I moved the var audioPlayer: AVAudioPlayer declaration … Read more

Swift: ‘Hashable.hashValue’ is deprecated as a protocol requirement;

As the warning says, now you should implement the hash(into:) function instead. func hash(into hasher: inout Hasher) { switch self { case .mention: hasher.combine(-1) case .hashtag: hasher.combine(-2) case .url: hasher.combine(-3) case .custom(let regex): hasher.combine(regex) // assuming regex is a string, that already conforms to hashable } } It would be even better (in case of … Read more

What does the SwiftUI `@State` keyword do?

The @State keyword is a @propertyWrapper, a feature just recently introduced in Swift 5.1. As explained in the corresponding proposal, it’s sort of a value wrapper avoiding boilerplate code. Sidenote: @propertyWrapper has previously been called @propertyDelegate, but that has changed since. See this post for more information. The official @State documentation has the following to … Read more

‘Module was not compiled for testing’ when using @testable

In your main target you need to set the Enable Testability build option to Yes. As per the comment by @earnshavian below, this should only be used on debug builds as per apple release notes: “The Enable Testability build setting should be used only in your Debug configuration, because it prohibits optimizations that depend on … Read more

Module compiled with Swift 5.1 cannot be imported by the Swift 5.1.2 compiler

OK, Turns out if you watch the WWDC video, they explain it: https://developer.apple.com/videos/play/wwdc2019/416/ You need to set the Build Settings > Build Options > Build Libraries for Distribution option to Yes in your framework’s build settings, otherwise the swift compiler doesn’t generate the neccessary .swiftinterface files which are the key to future compilers being able … Read more

tech