Questions tagged [swift5]

Use this tag only for questions directly related to changes in version 5 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 5 is a version of the Swift language developed by Apple and was released March 26th, 2019 with Xcode 10.2. The language is open source and available on GitHub (see ).

Swift 5 follows and .

Swift 5 Release Notes for Xcode 10.2.

3158 questions
22
votes
10 answers

iOS 13 Schedule iOS background tasks

I am implementing BackgroundTasks Framework for updating the data. But I got the below issue Could not schedule refreshApp: Error Domain=BGTaskSchedulerErrorDomain Code=1 "(null)" Could not schedule data featch: Error…
Gurjinder Singh
  • 9,221
  • 1
  • 66
  • 58
22
votes
1 answer

UIAlertController and UIViewAlertForUnsatisfiableConstraints error

I upgraded to Xcode 10.2 yesterday and started using Swift 5 and notice this error when bringing up my UIAlertController photo prompt. I don't remember seeing it in Xcode 10.1 Will attempt to recover by breaking constraint…
bvh
  • 443
  • 4
  • 10
21
votes
6 answers

CompileSwiftSources normal x86_64 com.apple.xcode.tools.swift.compiler (in target 'Pageboy' from project 'Pods')

I am getting the below error when I build my iOS project in Xcode 13.0 for Simulator 15 with Swift 5.5
umar farooq
  • 350
  • 1
  • 2
  • 8
21
votes
2 answers

How to await x seconds with async await Swift 5.5

How do I use the new Swift 5.5 await keyword to wait for a duration of time? Normally, with completion handlers, you would have something like this by using DispatchQueue's asyncAfter(deadline:execute:): func someLongTask(completion: @escaping (Int)…
George
  • 25,988
  • 10
  • 79
  • 133
21
votes
1 answer

Using @unknown default in swift 5 enum : How to suppress "Default will never be executed" warning?

Let's say I have an existing code as follows: enum SomeEnumCases { case existing case alreadyExisting } func doSomething(withEnums enumCase: SomeEnumCases) { switch enumCase { case .existing: print("This case was already existing") …
Mehul Parmar
  • 3,599
  • 3
  • 26
  • 42
20
votes
1 answer

How to access an actor-isolated property

I try to check the actor's behavior. This is a new feature provided by Swift5.5. I've created a playground with an example code from the official documentation swift.org: import Foundation actor TemperatureLogger { let label:…
Denis Kreshikhin
  • 8,856
  • 9
  • 52
  • 84
20
votes
6 answers

How can I make a background color with opacity on a Sheet view?

I'm currently developing an application using SwiftUI. I'm looking for some way to make a background color with opacity on a Sheet view. is there any way to do that? I've tried to do that with a code below, I can change the color with opacity…
Tio
  • 944
  • 3
  • 15
  • 35
20
votes
7 answers

Conditional property in SwiftUI

How can I add an additional property based on a condition? With my code below I get the error: Cannot assign value of type 'some View' (result of 'Self.overlay(_:alignment:)') to type 'some View' (result of…
Ben Keil
  • 1,050
  • 1
  • 10
  • 30
20
votes
2 answers

How to hide NavigationView Bar in SwiftUI

I cannot hide NavigationView bar. I tried both variants: Code 1: public var body: some View { NavigationView { MasterView() .navigationBarHidden(true) } } Code 2: public var body: some View { NavigationView { …
Bohdan Savych
  • 3,310
  • 4
  • 28
  • 47
20
votes
2 answers

Generic type 'Result' specialized with too few type parameters (got 1, but expected 2)

I just wanted to include Result in my project and am running across a few issues. It seems to me as if Alamofire (which is already a dependency) defines its own Result type throwing problems when trying to write functions that return results. For…
AYohannes
  • 625
  • 2
  • 7
  • 18
19
votes
2 answers

How to make a VStack Clickable to show alert in SwiftUI

I have a VStack with image and a text, I need to make it clickable so I can show and alert to the user. I have tried onTapGesture method but I'm able to print the statement but alert is not showing up. Is there any alternate way to get the…
Denzil
  • 415
  • 5
  • 13
19
votes
6 answers

Delegate methods in child class sometimes not called with Swift 5 compiler

EDIT: As sunshinejr pointed out here, this has been fixed and will be released together with the next Xcode/Swift version. I've seen a lot of weird behaviour after updating Xcode 10.1 to Xcode 10.2, both with Swift 4 and Swift 5 codebases. One of…
Jan Erik Schlorf
  • 2,050
  • 21
  • 36
19
votes
5 answers

Get string md5 in Swift 5

In Swift 4 we could use var md5: String? { guard let data = self.data(using: .utf8) else { return nil } let hash = data.withUnsafeBytes { (bytes: UnsafePointer) -> [UInt8] in var hash: [UInt8] = [UInt8](repeating: 0, count:…
Valentin Shamardin
  • 3,569
  • 4
  • 34
  • 51
18
votes
2 answers

Where is Swift Package Manager cache located (Swift 5.7)?

After retagging a git commit I'm no longer able to fetch the package, because SP Manager uses some cache which I can't find and clean. Getting error: Revision 30c16cab9c718416fee2191ff2ac0b6f91eeb511 for base remoteSourceControl…
Bretsko
  • 608
  • 2
  • 7
  • 20
18
votes
5 answers

SwiftUI: How to persist @Published variable using UserDefaults?

I want a @Published variable to be persisted, so that it's the same every time when I relaunch my app. I want to use both the @UserDefault and @Published property wrappers on one variable. For example I need a '@PublishedUserDefault var…
Sreeni
  • 205
  • 2
  • 6