swift5

New Swift 5 warnings for Objective-C enums: how to get rid of them?

空扰寡人 提交于 2019-12-08 19:18:16
问题 As of Xcode 10.2, when using enums I've defined in Objective-C, but in a Swift 5 switch statement, I get the following warning, even if I've exhausted all the possible enum values. Switch covers known cases, but 'MyObjectiveCEnumName' may have additional unknown values Xcode is telling me I should fix this by Handle unknown values using "@unknown default" Why is this happening and what can I do about it? Example Objective-C enum typedef NS_ENUM(NSUInteger, CardColor) { CardColorBlack,

Singletons in Swift 5

梦想与她 提交于 2019-12-08 15:33:38
问题 Here's precisely how I make a singleton, public class Model { static let shared = Model() // For ocd friends. Add this line: private init() {} func test()->Double { return 3.33 } } then elsewhere... class ViewController:UIViewController { override func viewDidLoad() { super.viewDidLoad() print("Holy singleton test, Batman! \( Model.shared.test() )") } } What about in Swift 5? Any new dramas or insights? Have they perhaps added "actual" singletons, or? 回答1: Nothing new. It remains the same in

how Add mirror image to 2d Box corners

ぃ、小莉子 提交于 2019-12-08 11:42:40
问题 hello friends i need to add mirror image in right corner and bottom . i create the type of view with the help of this answer how to create a view like this shape in swift? but i am not able to add image in right corner and bottom 回答1: Current approach is somewhat different from the previous one. Previously i've drawn the right and bottom corner and resized the image such that, the appearance is asked in that question. But in this question, that approach won't work anymore. First reason is

What is @dynamicCallable in Swift?

只愿长相守 提交于 2019-12-08 11:29:42
问题 From Apple's documentation: The @dynamicCallable attribute lets you call named types like you call functions using a simple syntactic sugar. The primary use case is dynamic language interoperability . Why would you want to use an @dynamicCallable instead of direct approch? 回答1: @dynamicCallable is a new feature of Swift 5. From Paul Hudson's article on "How to use @dynamicCallable in Swift" (emphasis mine): SE-0216 adds a new @dynamicCallable attribute to Swift, which brings with it the

Problem with SQLite.swift after migration to Swift 5

☆樱花仙子☆ 提交于 2019-12-08 05:03:01
问题 I use SQLite.swift and after upgrading to Swift 5 an error appears in the library. Please help me rewrite the method. Error: 'withUnsafeBytes' is deprecated: use `withUnsafeBytes<R>(_: (UnsafeRawBufferPointer) throws -> R) rethrows -> R` instead Code: public var datatypeValue: Blob { return withUnsafeBytes { (pointer: UnsafePointer<UInt8>) -> Blob in return Blob(bytes: pointer, length: count) } } 回答1: Till SQLite.swift doesn't release any update with the fix you could try modify manually the

This copy of libswiftCore.dylib requires an OS version prior to 12.2.0

余生长醉 提交于 2019-12-04 20:46:37
问题 The app crashes on launch when running from XCode 10.2 (before and after Swift 5.0 migration) with this on console This copy of libswiftCore.dylib requires an OS version prior to 12.2.0. I understand the error, but not sure what is required to fix this. 回答1: Someone in my team fixed the issue. It is a fix in BUCK providing /usr/lib/swift as a first argument for runtime search paths to linker if iOS >= 12.2, it should load platform libraries. 回答2: Got it fixed in our ObjectiveC-only project by

iOS SwiftUI Searchbar and REST-API

你说的曾经没有我的故事 提交于 2019-12-04 18:27:45
I'm experimenting with SwiftUI and would like to fetch an update from my REST API with a search string. However, I'm not sure how to bring the two components together now. I hope you have an idea. Here my Code: struct ContentView: View { @State private var searchTerm: String = "" @ObservedObject var gameData: GameListViewModel = GameListViewModel(searchString: ### SEARCH STRING ???? ###) var body: some View { NavigationView{ Group{ // Games werden geladen... if(self.gameData.isLoading) { LoadingView() } // Games sind geladen: else{ VStack{ // Suche: searchBarView(text: self.$searchTerm) //

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

你。 提交于 2019-12-04 10:40:19
问题 From Swift 5, new case attribute @unknown is introduced. What is the exact difference when @unknown is being used and not being used? In which case we have to use @unknown keyword? 回答1: 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

UIAlertController's actionSheet gives constraint error on iOS 12.2 / 12.3 [duplicate]

纵然是瞬间 提交于 2019-12-04 07:32:53
问题 This question already has answers here : Swift default AlertViewController breaking constraints (2 answers) Closed 6 months ago . On iOS 12.2. while using UIAlertController's actionSheet Xcode, gives constraint error anyone having this problem This same code runs on iOS 12.1 with no error I have tested this code on Xcode 10.2 and 10.1 class ViewController: UIViewController { let Click : UIButton = { let button = UIButton(type: UIButton.ButtonType.system) button

Map value in particular key in array of dictionary

心不动则不痛 提交于 2019-12-04 05:44:43
问题 Map value the particular key wherever presents in array of dictionary and replace it in same array. We need to update pan_card key 0 to 1 , in occurence of array of dictionary. let keyToUpdate = "pan_card" var arrayOfDictionary = [[String:Any]]() var firstDict = [String:Any]() firstDict["passport"] = 0 firstDict["ration_card"] = 0 firstDict["pan_card"] = 0 var arrayDict = [String : Any]() arrayDict["currentObject"] = firstDict arrayDict["title"] = "Documents list" var secondDict = [String:Any