Questions tagged [swift4]

Use this tag only for questions directly related to changes in version 4 of Apple's Swift programming language. Use the tag [swift] for more general language questions, or the tags [ios], [cocoa], [apple-watch] etc. for questions about developing on Apple platforms.

Swift 4 is the fourth version of the Swift language developed by Apple that was released in 2017. The language is open source and available on Github (see ).

The development of Swift 4 and its goals can be viewed on the Swift Programming Language Evolution repository on GitHub.

5684 questions
30
votes
5 answers

Failed to load optimized model - GoogleMaps SDK IOS

I am getting this error after installing Google Maps SDK from CocoaPods. CoreData: annotation: Failed to load optimized model at path…
Nabeel
  • 841
  • 1
  • 10
  • 23
29
votes
8 answers

Swift 4 JSON Decodable simplest way to decode type change

With Swift 4's Codable protocol there's a great level of under the hood date and data conversion strategies. Given the JSON: { "name": "Bob", "age": 25, "tax_rate": "4.25" } I want to coerce it into the following structure struct…
Dru Freeman
  • 1,766
  • 3
  • 19
  • 41
29
votes
3 answers

Code migration from Swift 2.x to Swift 4

We have big enough project which is built up with Swift 2.x and now Apple has just released Swift 4 so to move forward for latest version of Swift which path we can choose... Do we need to migrate our code to Swift 3 first? Or we can directly…
RayofHope
  • 1,187
  • 2
  • 14
  • 30
28
votes
2 answers

Cannot convert value of type Substring to expected argument type String - Swift 4

Trying to get substring of String and append it to array of Strings: var stringToSplit = "TEST TEXT" var s = [String]() let subStr = anotherString[0 ..< 6] s.append(subStr) // <---- HERE I GET THE ERROR
MBH
  • 16,271
  • 19
  • 99
  • 149
27
votes
5 answers

How to generate an UIImage from AVCapturePhoto with correct orientation?

I am calling AVFoundation's delegate method to handle a photo capture, but I am having difficulty converting the AVCapturePhoto it generates into an UIImage with the correct orientation. Although the routine below is successful, I always get a…
Andre Guerra
  • 1,117
  • 1
  • 9
  • 18
26
votes
3 answers

Swift Decodable Optional Key

(This is a follow-up from this question: Using Decodable protocol with multiples keys.) I have the following Swift code: let additionalInfo = try values.nestedContainer(keyedBy: UserInfoKeys.self, forKey: .age) age = try…
Charlie Fish
  • 18,491
  • 19
  • 86
  • 179
26
votes
5 answers

Adjust position of bar button item when using large titles with iOS 11

I am using the large title navbar with iOS 11, but when I add a bar button item it looks weird positioned in the same location as the original title navbar. I would like to move the bar button item down when the title is large, and move it back into…
Ali
  • 1,002
  • 1
  • 11
  • 21
26
votes
1 answer

Swift 4 "This class is not key value coding compliant"

I have a Swift library which is heavily reliant on obj.valueForKey() from NSObject. After migrating to Swift 4 I've found that these calls always crash with the error "this class is not key value coding-compliant for the key..." unless the property…
user1537360
  • 4,751
  • 6
  • 26
  • 22
26
votes
1 answer

iOS: Using Swift 4 when targeting iOS 9

Swift 4 is adding some really cool features, like strongly typed keypaths and JSON encoding/decoding using Codable. I would like to use these new features while still targeting iOS 9 and above. As far as I understand, Swift language version is not…
Tom Kraina
  • 3,569
  • 1
  • 38
  • 58
24
votes
2 answers

toUIntMax() and toIntMax() removed from Swift 4

What has replaced the method toUIntMax() and the method toIntMax() in Swift 4 ? The error occurred within the FacebookCore framework. Any help would be appreciated
techcoderx
  • 602
  • 1
  • 7
  • 21
23
votes
3 answers

What does @objc dynamic var mean in Swift 4

Could you briefly explain what @objc and dynamic mean in Swift 4 using Xcode 9.x? With tries and errors and following articles in the stackoverflow, I have eventually achieved this snippet to work. But I would like to know a little bit about those…
Tora
  • 970
  • 1
  • 8
  • 15
23
votes
5 answers

How to change the UIPickerView text color?

The default UIPickerView color for text is black. There has been some updates to the language in Swift4. I have found my own solution and answered below.
Steve B
  • 861
  • 1
  • 7
  • 9
22
votes
3 answers

Swift Codable with dynamic keys

I have JSON structure as: "periods": { "2018-06-07": [ { "firstName": "Test1", "lastName": "Test1" } ], "2018-06-06": [ { "firstName": "Test1", "lastName": "Test1" } ] } I…
Masta
  • 461
  • 1
  • 3
  • 7
22
votes
2 answers

Thread safe singleton in swift

I have and Application which has a singleton that stores information across the whole app. However, this is creating some data race issues when using the singleton from different threads. Here there is a very dummy and simplistic version of the…
nikano
  • 1,136
  • 1
  • 8
  • 18
22
votes
10 answers

Picker Error Message on Exit (encountered while discovering extensions: Error Domain=PlugInKit Code=13) With Swift 4 - Xcode 9

Similar to PhotoPicker discovery error: Error Domain=PlugInKit Code=13 and also to https://forums.developer.apple.com/thread/82105 BUT I have tried all of these suggestions and still get an error in the debug log. Running Swift 4 XCode 9A235 What…
john
  • 505
  • 1
  • 7
  • 15