-
Notifications
You must be signed in to change notification settings - Fork 466
removed project warnings #683
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
68b0dd5
dea600c
076daf0
1381c98
68d6bb0
efd6672
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -106,3 +106,12 @@ extension Array where Element: BinaryInteger { | |
return sorted_data[index] | ||
} | ||
} | ||
|
||
// MARK: - Conversion | ||
|
||
/// Transforms `[Any?]` into `[AnyObject]` | ||
extension Array where Element == Any? { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This is the suggested update: /// Transforms into `[AnyObject]`
extension Array {
func toAnyObjectArray() -> [AnyObject] {
self as [AnyObject]
}
} |
||
func toAnyObject() -> [AnyObject] { | ||
self.map { $0 as AnyObject } | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could fail, since Any is more broad that AnyObject is, so the casting could fail. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not see how this can cause problems. @yaroslavyaroslav Could you please give more explanation/examples? It's said that all classes implicitly conform to Did some research and found that casting value types to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lol, why did they do that? Like now there's completely no difference between There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is still some difference when it comes to casting back to the original type. I cannot explain that in detail but for example if we cast There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Actually I'd consider this as a bug of those thing that is casting to AnyObject for Objective-C environment. But I don't sure though. |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// | ||
// ArrayExtensionTests.swift | ||
// Created by albertopeam on 25/11/22. | ||
// | ||
|
||
@testable import Web3Core | ||
import XCTest | ||
import BigInt | ||
|
||
final class ArrayExtensionTests: XCTestCase { | ||
func testToAnyObjectEmpty() { | ||
let result = [].toAnyObject() | ||
XCTAssertEqual(result.count, 0) | ||
} | ||
|
||
func testToAnyObjectNils() throws { | ||
let result = [nil, nil].toAnyObject() | ||
XCTAssertEqual(result.count, 2) | ||
XCTAssertTrue(result.first is NSNull) | ||
XCTAssertTrue(result.dropFirst().first is NSNull) | ||
} | ||
|
||
func testToAnyObjectNilAndNonNils() throws { | ||
yaroslavyaroslav marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let result = [ | ||
1, | ||
nil, | ||
"2", | ||
NSNull(), | ||
Data(hex: "FA"), | ||
BigInt(3), | ||
BigUInt(4), | ||
EthereumAddress(Data(count: 20)) | ||
].toAnyObject() | ||
XCTAssertEqual(result.count, 8) | ||
XCTAssertEqual(result.first as? Int, 1) | ||
XCTAssertTrue(result.dropFirst(1).first is NSNull) | ||
XCTAssertEqual(result.dropFirst(2).first as? String, "2") | ||
XCTAssertTrue(result.dropFirst(3).first is NSNull) | ||
XCTAssertEqual(result.dropFirst(4).first as? Data, Data(hex: "FA")) | ||
XCTAssertEqual(result.dropFirst(5).first as? BigInt, BigInt(3)) | ||
XCTAssertEqual(result.dropFirst(6).first as? BigUInt, BigUInt(4)) | ||
XCTAssertEqual(result.dropFirst(7).first as? EthereumAddress, EthereumAddress(Data(count: 20))) | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.