Skip to main content

All Questions

Tagged with
3 votes
1 answer
59 views

Why does Array's contains(_:) method cause an error when comparing an optional value with a non-optional value in Swift?

I’m working with Swift and encountered an issue when using the contains method on an array. The following code works fine: let result = ["hello", "world"].contains(Optional("...
mskim's user avatar
  • 33
0 votes
4 answers
132 views

Swift array `filter`, `map`, etc. (higher-order functions) when the closure needs to be `async`

Now that I'm living completely in a Swift 6 async/await world, I've suddenly hit a snag. When writing code of this sort (never mind what it does, just look at the form of the thing): let result = ...
matt's user avatar
  • 537k
-1 votes
1 answer
53 views

How to have multidata type Swift arays

I would like to know if I can have a Swift array or dictionary with multiple types. For example: struct type1 { var t1: String } struct type2 { var t2: Int } var dataArray = [type1(t1: "...
Kitten Apps-Films's user avatar
-1 votes
1 answer
32 views

Trying to have multiple array items appended to a user-defaults property when in a UITableViewCell?

I have been trying to create a "saved features" tab for my app. I embedded a button into my table view cell (which had a star icon - FavouriteStatusButton). When selected it would append the ...
Train Lover's user avatar
1 vote
3 answers
92 views

Adding Elements to a KeyValuePair<X, Y>

I looked at this answer, and it appears the response may be "you can't get there, from here," but I have to try... I am building a dynamic SwiftUI Charts generator, and need to figure out ...
Chris Marshall's user avatar
1 vote
1 answer
45 views

Store an array of non-Codable structures in Swift [closed]

I want to store an array of non-Codable structures (= HabitConfiguration()) in UserDefaults. Here is my attempt which consists in placing in a "dictionary" the variables of this structure ...
Lucas Drouot's user avatar
0 votes
3 answers
95 views

How can I sort dates to nearest date in Swift

I started studying programming languages ​​quite recently The essence of the problem is this - in SwiftData I created a model with the property of the date of birth and by picker I want to sort from ...
noOne's user avatar
  • 1
0 votes
0 answers
27 views

SwiftData Transformable [String] Object [duplicate]

I'm trying to create a SwiftData object with a [String] property 'cited'. I've written a custom ValueTransformer, but I get fatalError message: SwiftData/SchemaProperty.swift:1212: Fatal error: ...
Атанас Начков's user avatar
0 votes
0 answers
29 views

Playing video using AVAsset player returns error "Cannot Open"

Im trying to make a cache system so that cache some videos in splash screen to have better user experience specially for first time opening the app here's what I did in my cache manager class ...
Qasem Zreaq's user avatar
0 votes
1 answer
67 views

SwiftUI DragGesture stops responding when removing the last item in a row of a 2D array mid-gesture

I’m building a SwiftUI view with draggable items organized in a 2D array (array of arrays). I want to allow items to be moved between rows while dragging, specifically moving the item mid-gesture once ...
lokredi's user avatar
  • 15
-8 votes
2 answers
74 views

Searching for a way to get unique words from an array of strings [closed]

I'm searching for a way to get all sorted unique words in Swift for an array of strings containing sentences For example: let complexArray = ["One large dog", "One small dog", &...
user1233894's user avatar
  • 1,776
0 votes
0 answers
24 views

Error “Could not materialize Objective-C class named ‘Array’ from declared attribute value type ‘Array’” [duplicate]

I’m trying to save data to a SwiftData database, but I keep running into this error: Could not materialize Objective-C class named "Array" from declared attribute value type "Array<...
Damiano Miazzi's user avatar
-4 votes
2 answers
119 views

How to split a Swift string into an array by spaces and special characters like question marks, exclamation points, and periods? [closed]

I'm trying to split a string in Swift into an array of words, but I want to separate the words not only by spaces but also by special characters like question marks (?), exclamation points (!), and ...
Yuuu's user avatar
  • 879
0 votes
1 answer
82 views

Why is my picker displaying the array reversed?

I'm learning Swift and I came across this problem. I made an array for US states, and when I pass it in the picker for some reason it just reverses it. I solved it temporarily by reversing the states ...
Dillon's user avatar
  • 1
1 vote
1 answer
56 views

How to correctly run AppleScript on Mail.app via NSAppleScript and parse results as a list of strings

I've the following code that I would like to use to get a list of the email accounts available within the Mail.app. import Foundation struct EmailAccounts { func getAccountNames() -> [String] {...
Konrad's user avatar
  • 18.7k

15 30 50 per page
1
2 3 4 5
688