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
36
votes
4 answers

Taking photo with custom camera iOS 11.0 Swift 4. Update error

I have a custom camera in my app and it worked fine, but after the new update I am getting this error: 'jpegPhotoDataRepresentation(forJPEGSampleBuffer:previewPhotoSampleBuffer:)' was deprecated in iOS 11.0: Use -[AVCapturePhoto…
0ndre_
  • 3,577
  • 6
  • 26
  • 44
36
votes
4 answers

init(colorLiteralRed:,green:,blue:,alpha:) deprecated in Swift 4

let startingColorOfGradient = UIColor(colorLiteralRed: 255/255, green: 255/255, blue: 255/255, alpha: 1.0).cgColor let endingColorOFGradient = UIColor(colorLiteralRed: 251/255, green: 247/255, blue: 234/255, alpha: 1.0).cgColor let gradient:…
Zeus Eternal
  • 427
  • 1
  • 4
  • 11
35
votes
6 answers

It gives errors when using Swift Static library with Objective-C project

I need to make swift static library for my requirement. I made swift static library which uses swift and Obj-c code. I have included Obj-c files via bridge file. I am able to compile swift static library without any error and get libMySwift.a file.…
Vishal Gabani
  • 421
  • 2
  • 5
  • 12
35
votes
3 answers

Swift Codable Decode Manually Optional Variable

I have the following code: import Foundation let jsonData = """ [ {"firstname": "Tom", "lastname": "Smith", "age": "28"}, {"firstname": "Bob", "lastname": "Smith"} ] """.data(using: .utf8)! struct Person: Codable { let firstName,…
Charlie Fish
  • 18,491
  • 19
  • 86
  • 179
35
votes
4 answers

Closure tuple does not support destructuring in Xcode 9 Swift 4

After the gloss project for Swift 4 in Xcode 9 I am getting following error which i have no idea Closure tuple parameter '(key: _, value: _)' does not support destructuring Code: extension Dictionary { init(elements: [Element]) { …
Mihir Mehta
  • 13,743
  • 3
  • 64
  • 88
34
votes
2 answers

Can't import packages using Swift 4 Package Manager

Trying to test Swift 4 using Xcode-beta (v9) on my machine and having issues with importing packages into a test project: Initiated project using swift package init --type executable Changed Package.swift and added 2 projects to try…
Timka
  • 1,769
  • 1
  • 20
  • 27
33
votes
3 answers

Decoding a JSON without keys in Swift 4

I'm using an API that returns this pretty horrible JSON: [ "A string", [ "A string", "A string", "A string", "A string", … ] ] I'm trying to decode the nested array using JSONDecoder, but it doesn't have a single key and I…
davidg
  • 651
  • 1
  • 7
  • 18
33
votes
7 answers

Swift 4 'substring(from:)' is deprecated: Please use String slicing subscript with a 'partial range from' operator

i've just converted my little app but i've found this error: 'substring(from:)' is deprecated: Please use String slicing subscript with a 'partial range from' operator my code is: let dateObj = dateFormatterFrom.date(from: dateStringa) if…
Raffaele Spadaro
  • 331
  • 1
  • 3
  • 3
32
votes
6 answers

Make UIColor Codable

struct Task: Codable { var content: String var deadline: Date var color: UIColor ... } There are warnings saying "Type 'Task' does not conform to protocol 'Decodable'" and "Type 'Task' does not conform to protocol 'Encodable'". I…
Lambdalex
  • 481
  • 1
  • 5
  • 10
32
votes
3 answers

non-nominal type X does not support explicit initialization

I'm trying to understand what I'm doing wrong with generics in swift. I created this sample playground import UIKit public protocol MainControllerToModelInterface : class { func addGoal() init() } public protocol…
Luca Bartoletti
  • 2,435
  • 1
  • 24
  • 46
32
votes
4 answers

Swift 4 Conversion error - NSAttributedStringKey: Any

I converted my app recently and I keep getting the error "Cannot convert value of type '[String : Any]' to expected argument type '[NSAttributedStringKey: Any]?' barButtonItem.setTitleTextAttributes(attributes, for: .normal) Whole code: class…
Eazy
  • 331
  • 1
  • 3
  • 7
32
votes
1 answer

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 from main thread only UI API called from background thread Group Purple Warning. My codes; var appDelegate =…
SwiftDeveloper
  • 7,244
  • 14
  • 56
  • 85
31
votes
2 answers

UITableViewRowAction was deprecated in iOS 13.0

I am trying to upgrade code of my project and found this warning func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? { let deleteRowAction = UITableViewRowAction(style: .destructive,…
user1828845
  • 1,304
  • 1
  • 10
  • 17
30
votes
8 answers

'Invalid bitcode version (Producer: '902.0.39.2_0' Reader: '900.0.37_0')'

I'm using Xcode 9.0. My pod file: pod 'Alamofire', '~> 4.3' pod 'SwiftyJSON' pod 'AlamofireSwiftyJSON' pod 'KSToastView', '0.5.7' pod 'SDWebImage', '~> 4.0' pod 'NVActivityIndicatorView' pod 'Firebase/Core' pod 'Firebase/Messaging' pod…
Himanshu Moradiya
  • 4,769
  • 4
  • 25
  • 49
30
votes
3 answers

Difference between flatMap and compactMap in Swift

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…
BilalReffas
  • 8,132
  • 4
  • 50
  • 71