Skip to content

Commit

Permalink
returnSelf
Browse files Browse the repository at this point in the history
  • Loading branch information
ytyubox committed Aug 6, 2021
1 parent 2c023c1 commit 3b65112
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 18 deletions.
9 changes: 6 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ let package = Package(
targets: [
.target(
name: "GenericProtocolVariable",
dependencies: []),
dependencies: []
),
.testTarget(
name: "GenericProtocolVariableTests",
dependencies: ["GenericProtocolVariable"]),
])
dependencies: ["GenericProtocolVariable"]
),
]
)
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ class ABSClass: Equatable {
Self.isEqual(lhs: lhs, rhs: rhs)
}

class func isEqual(lhs: ABSClass, rhs: ABSClass) -> Bool {
class func isEqual(lhs _: ABSClass, rhs _: ABSClass) -> Bool {
abstractFunction()
}

func isEqual(to other: ABSClass) -> Bool {
func isEqual(to _: ABSClass) -> Bool {
abstractFunction()
}
}
Expand Down
7 changes: 3 additions & 4 deletions Sources/GenericProtocolVariable/Generic/Generic.swift
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
//
/*
/*
* Created by 游宗諭 in 2021/8/4
*
*
* Using Swift 5.0
*
*
* Running on macOS 12.0
*/


public protocol Generic {
associatedtype AnyType
func getter() -> AnyType
Expand Down
10 changes: 4 additions & 6 deletions Sources/GenericProtocolVariable/Helper+abstractFunction.swift
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
//
/*
/*
* Created by 游宗諭 in 2021/8/4
*
*
* Using Swift 5.0
*
*
* Running on macOS 12.0
*/



func abstractFunction(file: StaticString = #file, line: UInt = #line) -> Never{
func abstractFunction(file: StaticString = #file, line: UInt = #line) -> Never {
fatalError("abstract Function should never be call", file: file, line: line)
}
13 changes: 13 additions & 0 deletions Sources/GenericProtocolVariable/ReturnSelf/ReturnSelf.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
/*
* Created by 游宗諭 in 2021/8/4
*
* Using Swift 5.0
*
* Running on macOS 12.0
*/

public protocol ReturnSelf {
static func dequeue() -> ReturnSelf
var name: String { get }
}
1 change: 0 additions & 1 deletion Tests/GenericProtocolVariableTests/AnyEquatableTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import GenericProtocolVariable
import XCTest


// MARK: - Tests

final class Tests: XCTestCase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ final class GenericProtocolVariableTests: XCTestCase {

private struct TestingGeneric: Generic {
private let anyType: AnyType

init(_ anyType: AnyType) {
self.anyType = anyType
}

typealias AnyType = Int

func getter() -> AnyType {
anyType
}
Expand Down
52 changes: 52 additions & 0 deletions Tests/GenericProtocolVariableTests/ReturnSelfTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//
/*
* Created by 游宗諭 in 2021/8/5
*
* Using Swift 5.0
*
* Running on macOS 12.0
*/

import GenericProtocolVariable

// MARK: - TableViewCell

class TableViewCell: ReturnSelf {
var name: String { "a name" }

class func dequeue() -> ReturnSelf {
TableViewCell()
}
}

// MARK: - TestingReturnSelf

class TestingReturnSelf: TableViewCell {
override var name: String {
"another name"
}

override class func dequeue() -> ReturnSelf {
TestingReturnSelf()
}
}

import XCTest

// MARK: - ReturnSelfTests

final class ReturnSelfTests: XCTestCase {
func test() {
let list: [ReturnSelf.Type] = [
TableViewCell.self,
TestingReturnSelf.self,
]

let names = list
.map { $0.dequeue() }
.map(\.name)

XCTAssertEqual(names, ["a name",
"another name"])
}
}

0 comments on commit 3b65112

Please sign in to comment.