Cannot Convert Value of Type 'Foo!' to Expected Argument Type 'Foo!'

Cannot convert value of type 'Foo!' to expected argument type 'Foo!'

I figured this out. My view model was part of the tests target. After I set it to the run target only, the issue resolved. FYI.

Cannot convert value of type 'value' to expected argument type 'argument '

You are trying to force an optional to become non-optional. Swift doesn't like that. Instead, try this:

func startAltimeterUpdate() {
self.altimeter.startRelativeAltitudeUpdatesToQueue(NSOperationQueue.currentQueue()!,
withHandler: { (altdata, error) -> Void in
if let data = altdata {
self.handleNewMeasure(pressureData: data)
} else {
// altdata is nil
}
})
}

Cannot convert value of type '() - ()' to expected argument type '(LongPressGesture.Value) - Void' (aka '(Bool) - ()')

You would need to change your startTimer signature to accept LongPressGesture.Value (which resolves to Bool):

func startTimer(_ value : LongPressGesture.Value) {
//
}
LongPressGesture(minimumDuration: 0.25).onEnded(startTimer)

Cannot convert value of type 'String.Type' to expected argument type 'String!'

Lets walk through what deferredWampCRASigningBlock is:

((String!, ((String!) -> Void)!) -> Void)!

This is a void function that takes two things:

  • a String!
  • a void function that takes a String!

So when you call it, you must pass it those things. A string and a function.

let challenge = "challenge"
let finishBLock: String! -> Void = { signature in }
self.wamp?.config.deferredWampCRASigningBlock?(challenge, finishBlock)

From some of your comments, you seem to not know what challenge should be at this point. That suggests you should not be calling this function. This function is intended to be called by the part of the program that does know challenge is.

The confusion may be related to "when I try to instantiate it." The code you've given doesn't instantiate anything. It is trying to call the function. Perhaps what you really meant was to create the function and assign it:

self.wamp?.config.deferredWampCRASigningBlock = 
{ (challenge: String!, finishBlock: ((String!) -> Void)!) -> Void in
// ...
}

Cannot convert value of type 'BindingData Struct?' to expected argument type 'BindingData Struct'

In this case I think it should be enough just to unwrap binding, like

if selectedShirt != nil && showDetailShirt{

ShirtDetailView(shirtData: Binding($selectedShirt)!, showDetailShirt: $showDetailShirt,animation: _animation)
}

Cannot convert value of type 'String' to expected argument type '[Any]'

arrayRemove takes an array of values to be removed, you you'd want to use:

.arrayRemove([myArray![indexPath.row]])

See the added brackets

(https://firebase.google.com/docs/firestore/manage-data/add-data#update_elements_in_an_array)

That being said, be aware that you're force unwrapping multiple things with ! -- be aware that if one of these values is nil, your program will crash.

Cannot convert value of type 'Int' to expected argument type '()' when using onChange

You forgot to disregard the count, with _ in.

Text("").onChange(of: indices.count) { _ in

Cant parse JSON (nested dictionary) into ForEach with SwiftUI

Your JSON doesn't have any keys called list, which is why it's failing. Because it's a dynamically-keyed dictionary, you will want to decode it as [String:FeedValue].

I used a wrapper to keep the id from the original JSON, but you could also do some fancier decoding if you wanted to keep it in a one-level struct, but that's beyond the scope of this question.

let jsonData = """
{
"DCqkboGRytms": {
"name": "graffiti-brush-3.zip",
"downloads": "5",
"views": "9",
"sha256": "767427c70401d43da30bc6d148412c31a13babacda27caf4ceca490813ccd42e"
},
"gIisYkxYSzO3": {
"name": "twitch.png",
"downloads": "19",
"views": "173",
"sha256": "aa2a86e7f8f5056428d810feb7b6de107adefb4bf1d71a4ce28897792582b75f"
},
"bcfa82": {
"name": "PPSSPP.ipa",
"downloads": "7",
"views": "14",
"sha256": "f8b752adf21be6c79dae5b80f5b6176f383b130438e81b49c54af8926bce47fe"
}
}
""".data(using: .utf8)!

struct FeedValue: Codable {
let name, downloads, views, sha256: String
}

struct IdentifiableFeedValue : Identifiable {
let id: String
let feedValue: FeedValue
}

struct ContentView: View {
@State var list : [String:FeedValue] = [:]

var listItems: [IdentifiableFeedValue] {
list.map { IdentifiableFeedValue(id: $0.key, feedValue: $0.value) }
}

var body: some View {
List(listItems) { item in
Text(item.feedValue.name)
}.onAppear {
do {
list = try JSONDecoder().decode([String:FeedValue].self, from: jsonData)
} catch {
print(error)
}
}
}
}

How to fix 'Cannot convert value of type '[Any]' to type 'String' in coercion' error in swift

Got the solution:

var arr = data[0]
yourString: String = (arr as AnyObject).description

Cannot convert value of type 'NSFetchRequestNSFetchRequestResult' to specified type 'NSFetchRequestT'

T.fetchRequest() returns a NSFetchRequest<NSFetchRequestResult>,
you have to explicitly cast it to the specific NSFetchRequest<T>:

let fetchRequest = T.fetchRequest() as! NSFetchRequest<T>
let asyncFetchRequest = NSAsynchronousFetchRequest(fetchRequest: fetchRequest) { result in
success(result.finalResult ?? [])
}


Related Topics



Leave a reply



Submit