Top "Swift4" questions

Use this tag only for questions directly related to changes in version 4 of Apple's Swift programming language.

Single line if statement in Swift

How would one convert the following to Swift from Objective-C? if (myVar) return; Swift does not use parentheses around the …

ios objective-c swift swift3 swift4
How do I use custom keys with Swift 4's Decodable protocol?

Swift 4 introduced support for native JSON encoding and decoding via the Decodable protocol. How do I use custom keys for …

json swift swift4 codable
With JSONDecoder in Swift 4, can missing keys use a default value instead of having to be optional properties?

Swift 4 added the new Codable protocol. When I use JSONDecoder it seems to require all the non-optional properties of my …

json swift swift4 codable
How can I deal with @objc inference deprecation with #selector() in Swift 4?

I'm trying to convert my project's source code from Swift 3 to Swift 4. One warning Xcode is giving me is about …

swift xcode swift4
How to build Swift 3 project on Xcode 9?

Xcode 9 Release Notes says that Swift 3 compilation is supported: One compiler for Swift 4 and Swift 3, Swift 4 and Swift 3 targets can …

ios xcode swift3 swift4 xcode9
UIImageJPEGRepresentation has been replaced by instance method UIImage.jpegData(compressionQuality:)

I've tried to upload a photo to Firebase but it's giving me this error. It was working before Xcode 10. I'm …

ios swift swift4 ios12
How to decode a nested JSON struct with Swift Decodable protocol?

Here is my JSON { "id": 1, "user": { "user_name": "Tester", "real_info": { "full_name":"Jon Doe" } }, "reviews_count": [ { "count": 4 } ] } Here is …

json swift swift4 codable
Swift 4 ,must be used from main thread only warning

When I using Swift4in Xcode 9 gives me UIApplication.delegate must be used from main thread only .... must be used …

appdelegate swift4 xcode9
navigation bar rightbaritem image-button bug iOS 11

This code works ok in ios10. i get my label and an image button which is the user photo profile, …

ios swift ios11 xcode9-beta swift4
'subscript' is unavailable: cannot subscript String with a CountableClosedRange<Int>, see the documentation comment for discussion

In Swift 4, I'm getting this error when I try to take a Substring of a String using subscript syntax. 'subscript' …

swift string swift4