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
8
votes
1 answer

Swift 5: Index of a Character in String

Before Swift 5, I had this extension working: fileprivate extension String { func indexOf(char: Character) -> Int? { return firstIndex(of: char)?.encodedOffset } } Now, I get a deprecated message: 'encodedOffset'…
Gizmodo
  • 3,151
  • 7
  • 45
  • 92
8
votes
1 answer

Swift 5: String.UTF16View.Index(encodedOffset: l) deprecated

I'm using this code to insert hyphens into a string for better word-wrapping. With Swift 5 I get the info that String.UTF16View.Index(encodedOffset: l) would be deprecated. But I can not figure out the correct parameters. Any ideas? import…
netshark1000
  • 7,245
  • 9
  • 59
  • 116
8
votes
1 answer

Would Swift 5 apps be able to run only on specific iOS versions?

Recently I have read a few articles about Swift 5 being ABI Stable (which basically means you won't need to pack app's own version of the Swift Dynamic Library within the App bundle) and here is the confusing part: because Swift will be embedded…
roxanneM
  • 853
  • 1
  • 7
  • 12
7
votes
1 answer

How to call async function asynchronously without awaiting for the result

Let's say I have the following functions. func first() async { print("first") } func second() { print("second") } func main() { Task { await first() } second() } main() Even though marking first function as async does not…
7
votes
2 answers

Recurring function in Swift 5.5 using async/await

I want to keep firing a function 5 seconds after it completes. Previously I would use this at the end of the function: Timer.scheduledTimer(withTimeInterval: 5, repeats: false) { self.function() } But I am wanting to use Swift 5.5's async/await. If…
Darren
  • 10,182
  • 20
  • 95
  • 162
7
votes
1 answer

Swift async/await equivalent of Promise Kit "when" pattern

I'm new to Swift, coming from JS, and I've started to build an iOS app. Initially I went down the road, using Promise Kit for the async stuff, as it seemed easier to me than other things I read about. Regardless, in JS, I use the following pattern a…
Kim
  • 856
  • 1
  • 11
  • 21
7
votes
2 answers

What is the correct way to include Playgrounds in a Swift Package?

When I publish a Swift Package, I like to include some Playgrounds to show examples of how to use the package. Prior to Swift 5.4, I was able to do this in a relatively straightforward way, but now none of my Playgrounds ever sees the contents of my…
B.T.
  • 610
  • 6
  • 20
7
votes
1 answer

Swift 5.5: Asynchronously iterating line-by-line through a file

In the "Platforms State of the Union" video of WWDC2021 at 28:00 it was mentioned that [Apple] even added support for asynchronously iterating line-by-line through a file in Foundation for macOS 12/iOS 15 and Swift 5.5. What is that new API, how…
YourMJK
  • 1,429
  • 1
  • 11
  • 22
7
votes
2 answers

SwiftUI Share Sheet Crashes iPad

I was following this tutorial https://jeevatamil.medium.com/how-to-create-share-sheet-uiactivityviewcontroller-in-swiftui-cef64b26f073 to add a simple share sheet to my swiftui app. It works properly on iPhones but crashes on iPad with this…
Boeggles
  • 59
  • 1
  • 6
7
votes
0 answers

Configure selection limit on Limited Library Picker

Considering user privacy I would like to implement a Limited Library Picker (introduced with iOS 14). Our app handles condition assessment of technical components by allowing the user to attach exactly one photo per component. For this we've been…
matthau
  • 71
  • 3
7
votes
1 answer

How add Export/Import Universal Type Identifier Icon to Xcode 12 Project?

I'm using Xcode 12 and I'm trying to adding Universal Type Identifier icon for export and import process. So I have tried below ways for creating the icon. added .png file to shared folder. created .icns file using .png file via online tool and…
7
votes
1 answer

How to get font style name from UIFont in Swift 5.1?

I need to write a custom font picker view in my ios project. when user click on font family name, i need to display fonts which are in particular family, i used name as particular text style in the family name. I couldn't find the standard way to…
7
votes
2 answers

How to calculate distance between two iOS devices using Multipeer connectivity(Wifi network)?

How to calculate the distance between two iOS devices using a wireless connection. I figure out we can calculate using BLE, using RSSI number. But the range of the device varies and the device placed in the room far away cannot be discovered. My…
ketaki Damale
  • 634
  • 7
  • 25
7
votes
5 answers

using bridging headers with module interfaces is unsupported Command CompileSwiftSources failed with a nonzero exit code

I have razor pay pod in my project for payment gateway and SWRevelViewController file for side bar controller. I selected the swift 5 and iOS version 13 and updated all the pods but still getting error error: using bridging headers with module…
sagarmahi onwork
  • 87
  • 1
  • 1
  • 7
7
votes
1 answer

UserDefault property wrapper not saving values iOS versions below iOS 13

I am using a property wrapper to save my User Default values. On iOS 13 devices, this solution works great. However on iOS 11 and iOS 12, the values are not being saved into User Defaults. I read that property wrappers are backwards compatible so I…
dayloosha
  • 123
  • 4