简体   繁体   中英

Swift Cannot invoke 'someFunction' with an argument list of type '(SomeType, Block (($T9) ->

I'm working on an iOS Project which is using Swift and the Firebase API.
Somehow I'm getting the following error on this query:

ref.queryOrderedByKey().queryLimitedToFirst(limit as UInt)
   .observeSingleEventOfType(FEventType.Value, withBlock: { 
       snapshot in

       var n = News(
             snapshot.key,
             snapshot.value["value1"] as? String,
             snapshot.value["value2"] as? String,
             snapshot.value["value3"] as? Int)

       result!.append(n)
})

The error:

Cannot invoke 'observeSingleEventOfType' with an argument list of type '(FEventType, withBlock: (($T9) -> ($T9) -> §T8) -> (($T9) -> ($T9) -> §T8)'

I'm pretty sure it is because the compiler is not recognizing the block or the type of snapshot correctly, but I don't know how to fix this in combination with blocks.

Update:
The Objective-C Header for the called function looks like this:

  • (void) observeSingleEventOfType:(FEventType)eventType withBlock:(void (^)(FDataSnapshot* snapshot))block;

Try UInt(limit) in place of limit as UInt .

I'm not sure what type limit is in your case, but I was able to get a similar error when limit was an Int . Doing the replacement fixed the issue for me.

I'm not familiar with Firebase API but you can (and probably should) define the type of snapshot in the block as in:

withBlock: {
(snapshot: SnapshotType) in 
    yourCode()
}

if the block returns a value you need to modify it as:

withBlock: {
(snapshot: SnapshotType) -> ReturnType in 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM