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

why is it legal to mutate an actor's nonSendable property?

The following code is legal in Swift 5.5 (beta): class Dog { var name = "rover" var friend : Dog? = nil } actor MyActor { let dog = Dog() } func test() async { let act = MyActor() act.dog.name = "fido" act.dog.friend = Dog() …
matt
  • 515,959
  • 87
  • 875
  • 1,141
9
votes
1 answer

Can I use actors in Swift to always call a function on the main thread?

I recently saw that Swift had introduced concurrency support with the Actor model in Swift 5.5. This model enables safe concurrent code to avoid data races when we have a shared, mutable state. I want to avoid main thread data races in my app's UI.…
Pranav Kasetti
  • 8,770
  • 2
  • 50
  • 71
9
votes
1 answer

Error of 'self' used before 'self.init' call or assignment to 'self' on init in a different module

I have checked questions sharing the same topic but none address this weird behaviour I am experiencing: Say I have a simple old school struct: struct Person { var name: String var age: Int } And I want to overload the init in an extension…
Hudi Ilfeld
  • 1,905
  • 2
  • 16
  • 25
9
votes
4 answers

How to capture high resolution image from UIView

I hope you all are safe. I know this question asked several times but not getting a perfect answer. I just wanted to capture an image from UIView with high resolution the main this is that image should not be a blur. I have tried this code extension…
seggy
  • 1,176
  • 2
  • 18
  • 38
9
votes
2 answers

How to Push from presented ViewController?

What I want to do is: VC1 -> present VC2 -> push VC3 this is the normal flow I want to make. after that on back button(on each VC have back button) I required to show user as moving back: VC3 -> present VC2 -> VC1 How do I achieve this kind of…
manoj kashyap
  • 143
  • 2
  • 9
9
votes
2 answers

Section Header zIndex in UICollectionView CompositionalLayout - iOS 13

For some reason in new collectionview compositional layout zIndex property for section header is not working. I have tried below code to achieve the behaviour. func configureCategorySectionLayout() -> NSCollectionLayoutSection { let itemSize…
CrackIt
  • 606
  • 1
  • 5
  • 15
9
votes
3 answers

Is it possible to set a character limit on a TextField using SwiftUI?

[RESOLVED] I am using a codable struct which stores the object values retrieved from an API call so I have amended my TextField using Cenk Belgin's example, I've also removed extra bits I've added in so if anyone else is trying to do the same thing…
Oliver
  • 161
  • 2
  • 9
9
votes
1 answer

Swift 5 Default Decododable implementation with only one exception

Is there a way to keep Swift's default implementation for a Decodable class with only Decodable objects but one exception? So for example if I have a struct/class like that: struct MyDecodable: Decodable { var int: Int var string: String …
iVentis
  • 993
  • 6
  • 19
9
votes
1 answer

How can I use Foundation's URLRequest type on Linux?

When I try to use the struct URLRequest from Foundation, I get an error when compiling with swift 5.1.1. The same code works fine with swift 5.0.1. Example: given file Foo.swift with content import Foundation print(URLRequest.self) With Swift 5.0.1…
tarleb
  • 19,863
  • 4
  • 51
  • 80
9
votes
1 answer

"Implicitly unwrapped property" warning?

I have a class where I have a property like this: var residenceId: Int! When building with Xcode 10 and Swift 4.2 there are no issues. However, after installing Xcode 11 Beta and converting to Swift 5 I get the following warning: Implicitly…
pajevic
  • 4,607
  • 4
  • 39
  • 73
9
votes
1 answer

Is there a way to execute a function after an animation in SwiftUI?

In UIKit you can do something like this: UIView.animate(withDuration: TimeInterval, animations: { //animation }) { (Bool) in //code which will be executed after the animation } Is there anything like that in SwiftUI, or can you think of a…
Paul
  • 459
  • 7
  • 14
8
votes
3 answers

could not find module 'Alamofire' for target 'arm64-apple-ios-simulator'; found: x86_64-apple-ios-simulator, x86_64

I have updated xcode to 12.3, i am getting the new errors. could not find module 'Alamofire' for target 'arm64-apple-ios-simulator'; found: x86_64-apple-ios-simulator, x86_64 Command CompileSwift failed with a nonzero exit code
Ganesh Shetty
  • 302
  • 1
  • 4
  • 12
8
votes
3 answers

Swift – Function Body Length Violation or Line Length Violation

I have a function on Xcode (swift) that returns a very long array, that is one word per line. Like static func en() -> [String] { [ "a", "about", "above", "after", "again", "against", …
Duck
  • 34,902
  • 47
  • 248
  • 470
8
votes
1 answer

Throwing error while debug and run PO command in Xcode 12

When I am running application on simulator or device and try to use PO command during debug. Xcode is throwing error instead of printing value. It is happening after I have updated Xcode 12. error: virtual filesystem overlay…
VRAwesome
  • 4,721
  • 5
  • 27
  • 52
8
votes
2 answers

How to get SSID of currently connected Wifi Network in swift | iOS 14?

I need to get ssid of currently connected network. The reason I need this is to enable my app to perform certain functions when connected to a specific network. Now I cant seem to figure it out as in how to get the ssid? I've read online and…
Abu Bäkr
  • 313
  • 1
  • 2
  • 10