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
13
votes
3 answers

How can I conform a Swift actor to a protocol while preserving isolation?

Let's say we have the following goals: We want to use actors. We want to use dependency injection and resolve actors through DI. We want to hide our actors behind protocols so we can vary the implementation. We want to preserve actor isolation,…
Gregory Higley
  • 15,923
  • 9
  • 67
  • 96
13
votes
1 answer

UIDocumentPickerViewController - 'init(documentTypes:in:)' was deprecated in iOS 14.0

Method is deprecated from iOS 14, so need support for both iOS 14 and later. And iOS 13 and earlier.
Ashvin
  • 8,227
  • 3
  • 36
  • 53
13
votes
2 answers

Change type to non-optional after get rid of nils by applying filter

let elements: [(Int?, Int?)] = [(1, 2), (2, 1), (3, nil), (nil, 3), (5, 6), (6, 5)] let result = elements.filter { $0.0 != nil } as! [(Int, Int?)] Is there a more clean way to get partly non-optional type as a result? Without…
Roman
  • 1,309
  • 14
  • 23
13
votes
3 answers

How to: Using Combine to react to CoreData changes in the background

I want to achieve the following: Whenever someone triggers a CoreData save (ie. NSManagedObjectContextDidSave notification gets sent), I'd like to perform some background calculation based the changed NSManagedObject. Concrete example: Assume in a…
Nicolas
  • 755
  • 9
  • 22
13
votes
5 answers

How can I center a placeholder text in a TextField

My code is as follow: TextField("Enter Your Email", text: self.$username) How can I make the placeholder "enter your email" be centered in the TextField?
Damion Silver
  • 491
  • 1
  • 4
  • 16
13
votes
1 answer

Google AdMob error after update to Xcode 11 Swift 5.1

Since I have updated to Xcode 11 the interstitial ads in my app won't load anymore. (Before that everything worked fine. The app was even released on the App Store. We are now creating an updated version of the app) I installed the Google AdMobs…
Daniel Götz
  • 131
  • 4
13
votes
2 answers

how to upload image (Multipart) using Alamofire 5.0.0-beta.3 (Swift 5)

I am working on uploading image using multipart. This Code Working fine in swift 4 and Alamofire 4. Please give any solution for this. public class func callsendImageAPI(param:[String:…
korat krunal
  • 133
  • 1
  • 1
  • 6
12
votes
1 answer

Converting non-sendable function value may introduce data races

I have a simple piece of code: struct ContentView: View { var body: some View { Text("Hello world!") .task { await myAsyncFunc() } } private func myAsyncFunc() async {} } This compiles…
George
  • 25,988
  • 10
  • 79
  • 133
12
votes
5 answers

SwiftUI: using view modifiers between different iOS versions without #available

I use the following code snippet (in Xcode 13 Beta 5 and deployment target set to 14.0) to apply view modifiers conditionally according to iOS version: struct ContentView: View { var body: some View { Text("Hello, world!") …
JAHelia
  • 6,934
  • 17
  • 74
  • 134
12
votes
1 answer

Covariant 'Self' type cannot be referenced from a stored property initializer

In the below code, I don't understand why I get the said error when using Self() ? The code just works fine if I replace it with Fireman() . final class Fireman { var numOfServices = 0 private init(){} static var shared = Self()…
Tilak Madichetti
  • 4,110
  • 5
  • 34
  • 52
12
votes
3 answers

How to move a view/shape along a custom path with swiftUI?

There doesn't seem to be an intuitive way of moving a view/shape along a custom path, particularly a curvy path. I've found several libraries for UIKit that allow views to move on a Bézier Paths (DKChainableAnimationKit,TweenKit,Sica,etc.) but I am…
Anthney
  • 735
  • 1
  • 7
  • 12
12
votes
4 answers

How to set the background color of a swiftui to lightGray?

I am currently trying to set the background color of a text field in SwiftUI to light gray. it is not working my code is this TextField("Enter Your Email", text: $username) .background(Color.lightGray) Any idea what could be wrong with it ? It…
Damion Silver
  • 491
  • 1
  • 4
  • 16
12
votes
4 answers

Getting currently focused UIScene when multiple connected scenes are active in foreground

I have a problem getting the current UIScene when multiple scenes are connected. Specifically, my app (iOS 13) supports multiple windows on the iPad. When I have two windows side by side and I access the apps connected scenes (with…
freshking
  • 1,824
  • 18
  • 31
11
votes
1 answer

Calling Swift async function from Objective-C

I am using the new Swift 5.5 features to create an async function: @MainActor @objc func updateStatus() async { /// do async stuff... } But when I try to call this method from Objective-C code, it doesn't show up in autocomplete and gives a…
Z S
  • 7,039
  • 12
  • 53
  • 105
11
votes
3 answers

Carthage build failed Xcode 12 12A7209 building

Carthage File contents: github "SwiftyJSON/SwiftyJSON" Error: Build Failed Task failed with exit code 1: /usr/bin/xcrun lipo -create…
Samrez Ikram
  • 591
  • 5
  • 15