Skip to content

Commit 0df12d6

Browse files
committed
Add custom operator to handle data
1 parent e333bb0 commit 0df12d6

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

macaron.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@
479479
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
480480
PRODUCT_BUNDLE_IDENTIFIER = tokyo.yagra.macaronTests;
481481
PRODUCT_NAME = "$(TARGET_NAME)";
482-
SWIFT_SWIFT3_OBJC_INFERENCE = On;
482+
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
483483
SWIFT_VERSION = 4.0;
484484
};
485485
name = Debug;
@@ -493,7 +493,7 @@
493493
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
494494
PRODUCT_BUNDLE_IDENTIFIER = tokyo.yagra.macaronTests;
495495
PRODUCT_NAME = "$(TARGET_NAME)";
496-
SWIFT_SWIFT3_OBJC_INFERENCE = On;
496+
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
497497
SWIFT_VERSION = 4.0;
498498
};
499499
name = Release;

macaron/MacaronCellData.swift

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,17 @@ public protocol MacaronCellDataType {
1212
var CellClassName: String { get }
1313
}
1414

15-
public extension MacaronCellDataType {
16-
public func handle(_ handler: (Self) -> Void) -> Self {
17-
handler(self)
18-
return self
19-
}
15+
16+
precedencegroup HandlingCondition {
17+
associativity: left
18+
higherThan: AssignmentPrecedence
19+
lowerThan: TernaryPrecedence
20+
}
21+
22+
infix operator <!: HandlingCondition
23+
public func <! <D>(d: D, handler: (D) -> Void) -> D where D: MacaronCellDataType {
24+
handler(d)
25+
return d
2026
}
2127

2228
open class MacaronCellData<Cell: MacaronCellType>: MacaronCellDataType {

macaronTests/macaronTests.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@ class macaronTests: XCTestCase {
1313

1414
override func setUp() {
1515
super.setUp()
16-
// Put setup code here. This method is called before the invocation of each test method in the class.
1716
}
1817

1918
override func tearDown() {
20-
// Put teardown code here. This method is called after the invocation of each test method in the class.
2119
super.tearDown()
2220
}
23-
24-
func testExample() {
25-
// This is an example of a functional test case.
26-
// Use XCTAssert and related functions to verify your tests produce the correct results.
21+
22+
func testCustomOperator() {
23+
let data = TextCellData(text: "hoge") <! {
24+
$0.text = "fuga"
25+
}
26+
XCTAssertEqual(data.text, "fuga")
2727
}
2828

2929
func testPerformanceExample() {

0 commit comments

Comments
 (0)