swift4.1

Decodable and JSON, 2 datatypes for same variable

蓝咒 提交于 2019-12-03 21:43:12
I'm using the Decodable protocol to decode some json, but I've run into a problem: I'm getting an answer back, where a longitude and a latitide can be either an interger (latitude = 0) if there's no geo location data added to the element, and a String (fx. latitude = "25.047880") if there's geodata available. Now when I decode the json, I don't know how to build my Struct, as the long and lat can't both be String and Int.. So I'm getting a decode error when fetching elements where both cases are represented. Any suggestions about how to solve this? I've tried with "Any" as datatype, but this

Status bar could not find cached time string image. Rendering in-process

我是研究僧i 提交于 2019-12-02 14:59:37
I get the above runtime message after I upgraded to Swift4.1 and Xcode 9.3. Before the upgrade I did not have this message in my console window. Status bar could not find cached time string image. Rendering in-process. comes up every few minutes as long as I have the App running. It sees to me there is no negative side effect, my App is running, as usual, I have not seen any problems. I use the standard Status Bar, have not changed to modify it in any way. Question 1: Would there be a problem originating from this warning under situations i have not come across yet? Question 2: Does anyone

What is Swift 4.1.50?

大兔子大兔子 提交于 2019-12-02 14:58:09
问题 I'm playing around with the Xcode 10 beta, and I noticed while doing compile-time checks of the Swift version number that projects with the Swift Language Version set to Swift 4 in their Build Settings are reporting as Swift 4.1.50 (betas 2, 3, and 4 do this; I didn't get a chance to test beta 1) . This strikes me as... bizarre, to say the least. The current AppStore version of Xcode, Xcode 9.4.1, reports its version as Swift 4.1.2 . So... What happened to Swift 4.1.3 through 4.1.49? Or is

Cast Any to Float always fails in swift4.1

守給你的承諾、 提交于 2019-12-01 15:00:40
问题 In the former version, to get a float value from a [String: Any] dictionary, I can use let float = dict["somekey"] as? Float , but in swift4.1, it doesn't work. It seems the type of dict["somekey"] has been implicitly inferred as Double before I get it, so casting from Double to Float always fails. I wonder if it is a new characteristic or just a bug. --Here is the update. I re-downloadeded an Xcode9.2 and did some experiments, now I think I figure out what's going on. Here is the test code:

@objc keyword extension subclass behaviour

北城以北 提交于 2019-11-29 01:44:35
Can someone explain why @objc keyword is needed here to compile the code? As I understood this keyword is used in order to work ObjC message method dispatch. But this is not an NSObject instance. class MyClass { } extension MyClass { @objc func extensionMethod() { /// THIS LINE print("A") } } class SubClass: MyClass { override func extensionMethod() { print("B") } } Does @objc keyword enable message dispatch as well as dynamic ? Or not? Does @objc keyword enable message dispatch as well as dynamic ? Not usually. Usually, the @objc attribute on its own just exposes a given class member to

@objc keyword extension subclass behaviour

无人久伴 提交于 2019-11-27 02:50:59
问题 Can someone explain why @objc keyword is needed here to compile the code? As I understood this keyword is used in order to work ObjC message method dispatch. But this is not an NSObject instance. class MyClass { } extension MyClass { @objc func extensionMethod() { /// THIS LINE print("A") } } class SubClass: MyClass { override func extensionMethod() { print("B") } } Does @objc keyword enable message dispatch as well as dynamic ? Or not? 回答1: Does @objc keyword enable message dispatch as well

Difference between flatMap and compactMap in Swift

Deadly 提交于 2019-11-26 16:41:07
问题 It seems like in Swift 4.1 flatMap is deprecated. However there is a new method in Swift 4.1 compactMap which is doing the same thing? With flatMap you can transform each object in a collection, then remove any items that were nil. Like flatMap let array = ["1", "2", nil] array.flatMap { $0 } // will return "1", "2" Like compactMap let array = ["1", "2", nil] array.compactMap { $0 } // will return "1", "2" compactMap is doing the same thing. What are the differences between these 2 methods?