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
17
votes
5 answers

Convert to Current Swift Syntax Failed - "No such module" (Swift 4, Xcode 9)

In Xcode 9, I am trying to do the automatic conversion to Swift 4. It fails with the following message: Convert to Current Swift Syntax Failed Please ensure that all selected targets build successfully with the currently configured Swift version…
Nikolay Suvandzhiev
  • 8,465
  • 6
  • 41
  • 47
17
votes
3 answers

Overlapping accesses to 'urlComponents', but modification requires exclusive access

I am trying to use the Lyft API with iOS 11 and Swift 4, and am receiving an error on the second line, which is Overlapping accesses to 'urlComponents', but modification requires exclusive access; consider copying to a local variable. I am…
John Harding II
  • 564
  • 1
  • 6
  • 20
17
votes
1 answer

Swift 4: 'substring(to:)' is deprecated

I'm having trouble converting my Swift 3 code to Swift 4. I've managed to translate everything else in the app successfully, but am having trouble with a single line of code: cleanURL = cleanURL.substring(to: cleanURL.index(before:…
JDev
  • 5,168
  • 6
  • 40
  • 61
17
votes
1 answer

UIAppearance Swift 4

After updating to Swift 4, I am getting a compiler error: Static member 'appearance' cannot be used on protocol metatype 'UIAppearance.Protocol' Here is my viewWillAppear method in my custom Tab Bar Controller subclass, I am setting the font of the…
Eli Whittle
  • 1,084
  • 1
  • 15
  • 19
16
votes
3 answers

How to fix Xcode 10 error 'Multiple commands produce..' after generating Core Data subclasses

I have created a brand new core data model for my project and I want to create some NSManagedObject Subclasses for it. After generating subclasses XCode throws some errors that reference a path to the /DerivedData folder. See my steps below and…
rednaxela
  • 661
  • 2
  • 9
  • 21
16
votes
4 answers

HMAC SHA256 in Swift 4

I have a string and a key, which i want to generate an HMAC SHA256 from it. Although i'm using 2 libs IDZSwiftCommonCrypto and CryptoSwift and this answer Nothing really worked for me. My source of truth are those 2…
Konstantinos Natsios
  • 2,874
  • 9
  • 39
  • 74
16
votes
1 answer

Save AVCaptureVideoDataOutput to movie file using AVAssetWriter in Swift

I've been looking all over the web and can't seem to find a tutorial or help in what I need. Using AVFoundation and the Dlib library I've created an app that can detect a face from real time video using the front camera on the phone. I'm doing this…
Hardy143
  • 577
  • 4
  • 13
16
votes
5 answers

How to show two columns in a CollectionView using swift4 in all devices

To show only two columns in a collectionView i am using this piece of code let layout = self.collectionView.collectionViewLayout as! UICollectionViewFlowLayout layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0) …
Gorib Developer
  • 587
  • 2
  • 13
  • 27
16
votes
3 answers

Swift 4 Codable: Converting JSON return String to Int/Date/Float

I'm going through some projects and removing JSON parsing frameworks, as it seems pretty simple to do with Swift 4. I've encountered this oddball JSON return where Ints and Dates are returned as Strings. I looked at GrokSwift's Parsing JSON with…
Adrian
  • 16,233
  • 18
  • 112
  • 180
16
votes
6 answers

Declarations from extensions cannot be overridden yet in Swift 4

I have recently migrated my code to Swift 4. There is an issue that I am facing with extensions, i.e.: Declarations from extensions cannot be overridden yet I have already read multiple posts regrading this issue. But none of them entertains the…
PGDev
  • 23,751
  • 6
  • 34
  • 88
16
votes
2 answers

Swift 4 Using KVO to listen to volume changes

I just updated to Swift 4 and Xcode 9 and got a (swiftlint) warning for the following code telling me that I should use KVO now: Warning: (Block Based KVO Violation: Prefer the new block based KVO API with keypaths when using Swift 3.2 or later.…
Eternal Black
  • 259
  • 2
  • 15
16
votes
2 answers

String, substring, Range, NSRange in Swift 4

I am using the following code to get a String substring from an NSRange: func substring(with nsrange: NSRange) -> String? { guard let range = Range.init(nsrange) else { return nil } let start = UTF16Index(range.lowerBound) let…
koen
  • 5,383
  • 7
  • 50
  • 89
16
votes
3 answers

Difference between fileprivate and private extension?

Swift 3.0 I know that fileprivate access level modifier limited using of function/property to source file where it was declared and private - limited to lexical scope where was declared. But it seems that this rule not apply for extensions. E.G.…
Bohdan Savych
  • 3,310
  • 4
  • 28
  • 47
15
votes
9 answers

Xcode 11 doesn't recognize Core data Entity

I just declared an entity called "Users" array: var UsersArray = [Users]() I got this error: use of unresolved identifiers "Users" hint : I did import CoreData and created the entity
CoderTn
  • 985
  • 2
  • 22
  • 49
15
votes
7 answers

Swift URL appendingPathComponent converts `?` to `%3F`

let url = URL(string: "https://example.com") let path = "/somePath?" let urlWithPath = url?.appendingPathComponent(path) After appending, the path /somePath? becomes somePath%3F. The ? becomes a %3F. Question Mark is replaced with the…