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
19
votes
2 answers

How do I disable the full swipe on a tableview cell in iOS11

UITableViewDelegate.h // Swipe actions // These methods supersede -editActionsForRowAtIndexPath: if implemented // return nil to get the default swipe actions - (nullable UISwipeActionsConfiguration *)tableView:(UITableView *)tableView…
Megan Moreno
  • 203
  • 2
  • 6
19
votes
7 answers

Migration to Swift 4 from Swift 3.2 giving "failed to import bridging header " error

As apple has released Xcode 9 beta version with Swift 4.0 support. I have been trying to upgrade my code to Swift 4.0 from Swift 3.2. But it keeps giving me failed to import bridging header error whereas my project build successfully. Xcode error…
Varun Mehta
  • 1,733
  • 3
  • 18
  • 39
19
votes
5 answers

How to build a xcode 9 project with Swift 4.0 using Pods in Swift 3?

I want the main module of my iOS App to compile Swift 4.0 while the CocoaPods module compiles swift 3. PS: Using Xcode 9 beta 2.
Sanf0rd
  • 3,644
  • 2
  • 20
  • 29
19
votes
2 answers

"'init' is deprecated" warning after Swift4 convert

In Swift3, I previously converted a Bool to an Int using the following method let _ = Int(NSNumber(value: false)) After converting to Swift4, I'm getting a "'init' is deprecated" warning. How else should this be done?
D. Cohen
  • 567
  • 1
  • 7
  • 22
18
votes
3 answers

How to do two concurrent API calls in swift 4

Thanks in advance for help, I have two API calls, both are concurrent and any call could be success first(I don't want call in sequence), after success of both calls, I have to stop my activity indicator and reload my tableView, Here is my code but…
King
  • 259
  • 1
  • 4
  • 12
18
votes
2 answers

Custom Font Not Working in WKWebView Swift

Trying to use custom font in WKWebView but no luck. let htmlString = "\(Utils.aboutUsText)" webView.loadHTMLString(htmlString, baseURL: nil) I can use…
iYousafzai
  • 1,021
  • 1
  • 10
  • 29
18
votes
2 answers

Inheritance of Encodable Class

I am writing a program using Swift 4 and Xcode 9.2. I have faced difficulties with writing encodable class (exactly class, not struct). When I am trying to inherit one class from another, JSONEncoder does not take all properties from sub class…
Alex
  • 1,038
  • 2
  • 12
  • 32
18
votes
4 answers

Swift structures: handling multiple types for a single property

I am using Swift 4 and trying to parse some JSON data which apparently in some cases can have different type values for the same key, e.g.: { "type": 0.0 } and { "type": "12.44591406" } I am actually stuck with defining my struct because…
errata
  • 5,695
  • 10
  • 54
  • 99
18
votes
4 answers

Swift 4 Codable Array's

So I have an API route that returns a JSON array of objects. For example: [ {"firstname": "Tom", "lastname": "Smith", "age": 31}, {"firstname": "Bob", "lastname": "Smith", "age": 28} ] I'm trying to envision how to use the new codable…
Charlie Fish
  • 18,491
  • 19
  • 86
  • 179
18
votes
3 answers

What is the best way to test if a CharacterSet contains a Character in Swift 4?

I'm looking for a way, in Swift 4, to test if a Character is a member of an arbitrary CharacterSet. I have this Scanner class that will be used for some lightweight parsing. One of the functions in the class is to skip any characters, at the…
Steven Grosmark
  • 1,275
  • 1
  • 12
  • 15
18
votes
7 answers

Swift 4: NSFilenamesPboardType not available. What to use instead for registerForDraggedTypes?

After migrating to Swift4 the following code raise compile error: public final class MediaItemView: NSView { public override init(frame frameRect: NSRect) { super.init(frame: frameRect) // error: 'NSFilenamesPboardType' is…
Vlad
  • 6,402
  • 1
  • 60
  • 74
18
votes
2 answers

sizeForItemAtIndexPath is not found in different swift versions

I am using UICollectionView but following method not found: func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize please suggest me it's…
Vikram Biwal
  • 2,618
  • 1
  • 25
  • 36
17
votes
6 answers

How can I accurately detect if a link is clicked inside UILabels in Swift 4?

I have managed to style the links without problem using NSMutableAttributedString but I am unable to accurately detect which character has been clicked. I have tried all the solutions in this question (that I could convert to Swift 4 code) but with…
Dan Bray
  • 7,242
  • 3
  • 52
  • 70
17
votes
2 answers

Listening to stdin in Swift

Currently I am trying to listen to user input from the command line in my swift application. I am aware of the readLine() method but it does not really fit my needs. I want to listen for data being inserted on the command line. Like when a user is…
grahan
  • 2,148
  • 5
  • 29
  • 43
17
votes
4 answers

Can't decode date in Swift 4

I'm currently trying to learn Swift and haven't gotten very far yet, so forgive me if this is an easy problem; I've been working on it for hours now and haven't been able to figure it out. I have a Codable class called Person. On this class I have a…
shawnseanshaun
  • 1,071
  • 1
  • 13
  • 25