Skip to content

Commit

Permalink
Merge pull request #15 from greymass/fixing-cast-error
Browse files Browse the repository at this point in the history
Fixing cast error causing iOS crash
  • Loading branch information
aaroncox authored Mar 5, 2024
2 parents a9e5559 + 33cf264 commit 93864a0
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Sources/EOSIO/ABIDecoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,16 @@ public extension ABIDecoder {
case is UInt.Type:
return UInt(try self.readVaruint()) as! T
case let abiType as ABIDecodable.Type:
return try abiType.init(fromAbi: self) as! T
let decodedAbiType = try abiType.init(fromAbi: self)

// Instead of forcefully casting, verify the type at runtime.
if let result = decodedAbiType as? T {
return result
} else {
// As a temporary solution, we'll just return an empty array whenever a non supported type is found.
// This is not ideal, but it's better than crashing the app.
return [] as! T
}
default:
throw Error.typeNotConformingToABIDecodable(type)
}
Expand Down

0 comments on commit 93864a0

Please sign in to comment.