Skip to main content

All Questions

Tagged with
0 votes
2 answers
74 views

func argument with an Array of mixed types (protocol), then call a static method of the protocol

Here are my structures (I can have lot more, that why I need a generic way to do with MyProtocol): protocol MyCustomCodable { static func buildQuery() } struct A: MyCustomCodable { ... } ...
Guillaume PELOUAS's user avatar
0 votes
0 answers
30 views

How to cast KeyPath<CNContact, Array<CNLabeledValue>> to KeyPath<CNContact, Any>

I need to put KeyPath values in an array of type Array<KeyPath<CNContact,Any>>. However, \CNContact.phoneNumbers fails to cast to KeyPath<CNContact,Any>. Here is my test code: let ...
daniel's user avatar
  • 946
0 votes
1 answer
162 views

Swift 5: Merging Two Generic Functions with <T: BinaryInteger> & <T:BinaryFloatingPoint> with Output Type Specified

What I want to Work My end goal is to have Array Data such as [Int], [UInt], [Float] passed through a generic function that converts any of these types and outputs the [UInt8] 0-255 values for pixel ...
KleinerWarden's user avatar
0 votes
0 answers
399 views

The best way to convert Array<Int32> to Array<Int> in Swift

I have Array<Int32> with large size and I want to convert it into Array<Int>. Then, I am using map function like this; let int32array = Array<Int32>(0..<1000000) let intarray = ...
jjjkkkjjj's user avatar
1 vote
1 answer
185 views

C-style pointer/array casting in Swift?

Is there any way I can cast an array of different integer sizes to another array type? For example, in C, I can do: unsigned char byteArray[] = { 0x1, 0x5, 0xF, 0x3, 0xA5, 0x3, 0x8, 0x8, 0xAB }; ...
Sylvan M.'s user avatar
  • 190
0 votes
1 answer
853 views

Swift type-variable to generic-type-variable

The error I get is unsurprising, but how would I accomplish something like this in Swift? let stringType = String.self let stringArrayType = Array<String>.self let stringArrayTypeFromVariable = ...
joehinkle11's user avatar
1 vote
1 answer
121 views

Swift: typecast output array in Collection where Iterator.Element == Foo

I have the following function, it iterates over an array of Foo, and creates a new array using the items in the original array, but with different colors: extension Collection where Iterator.Element =...
koen's user avatar
  • 5,707
0 votes
1 answer
42 views

How does Swift Array support valid Element subtype assignment?

I want to cast or assign a custom Swift Container Type to a "compatible" declared variable container-type like native Swift Array supports. The code below is a complete example with the problem ...
user1864957's user avatar
-1 votes
1 answer
214 views

Errors trying to convert type [Any] to JSON with Swift

I'm trying to convert an object type [Any] to a JSON or something I can use to access the attributes. Steps: I call a function from a library to connect to a bluetooth device and retrieve data from ...
user10816637's user avatar
2 votes
0 answers
98 views

Bridging between incompatible types in Swift using memory rebind

I have been trying to solve a problem in my app. I get an NSArray from an Objective-C API and need to read it as an array of double values in the Swift app. So the bridging needed is between NSArray ...
Divya Godayal's user avatar
0 votes
3 answers
107 views

convert value of type 'Result?' to type 'String'

I have problems to cast my array of type 'result' to an array of string. This is what I already tried: EDIT: I need the information as String type since I want to use the URL as image source. swift4 ...
Jake2Finn's user avatar
  • 536
1 vote
1 answer
137 views

How can I make an array that holds types?

I am trying to create an array that holds the class of the custom collectionView cell I would like to deque. Below I have provided an example of how I would like to use this array. cellType is a ...
user avatar
1 vote
2 answers
3k views

Swift - How to cast Any to Array \ Dictionary?

I'm trying to parse a json which has an array with Strings, Ints and Arrays So I'm to iterate on the json {["item1", 2, ["subItem1", "subitem2"] ]} members in the array: func parse(json : [Any]) ...
Aviram Netanel's user avatar
-3 votes
2 answers
834 views

Swift: how to convert a [String:Any] array to a specific array

I have this simple Struct: protocol DocumentSerializable { init?(dictionary:[String:Any]) } struct Item { var title:String var text:String? var dictionary:[String:Any] { ...
Vins's user avatar
  • 1,934
0 votes
1 answer
64 views

Cast a [[[Double]]] back to [Double]

I have a downloaded JSON file. Within it, there are repeating objects that are either 1 of 2 types - either a [Double] or a [[[Double]]]. I am trying to use a Codable protocol for a custom struct to ...
jingo_man's user avatar
  • 529

15 30 50 per page