Skip to content

Commit 121d657

Browse files
committed
Bug with structures fix.
1 parent f407ba3 commit 121d657

File tree

6 files changed

+39
-5
lines changed

6 files changed

+39
-5
lines changed

Diff for: .swift-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4.0.1
1+
4.1

Diff for: CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## [1.2.1](https://github.com/sinarionn/ReusableView/releases/tag/1.2.1)
6+
7+
Fixed bug with structures hidden behind protocols
8+
9+
510
## [1.2.0](https://github.com/sinarionn/ReusableView/releases/tag/1.2.0)
611

712
MacOS support added

Diff for: Plists/ReusableView.plist

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<key>CFBundlePackageType</key>
1616
<string>FMWK</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>1.2.0</string>
18+
<string>1.2.1</string>
1919
<key>CFBundleSignature</key>
2020
<string>????</string>
2121
<key>CFBundleVersion</key>

Diff for: ReusableView.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Pod::Spec.new do |s|
33
s.name = "ReusableView"
4-
s.version = "1.2.0"
4+
s.version = "1.2.1"
55
s.summary = "Reusable and NonReusable viewModel containers"
66

77
s.homepage = "https://github.com/sinarionn/ReusableView"

Diff for: Sources/Helpers.swift

+12-2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,21 @@ import Foundation
1010
import RxSwift
1111

1212
internal func associate(_ object: Any?, withValue value: Any?, by key: UnsafeRawPointer, policy: objc_AssociationPolicy = .OBJC_ASSOCIATION_RETAIN_NONATOMIC) {
13-
object.map{ objc_setAssociatedObject($0, key, value, policy) }
13+
object.map{ objc_setAssociatedObject($0, key, value.map(AssociationWrapper.init), policy) }
1414
}
1515

1616
internal func associated<T>(with object: Any, by key: UnsafeRawPointer) -> T? {
17-
return objc_getAssociatedObject(object, key) as? T
17+
let wrapper = objc_getAssociatedObject(object, key) as? AssociationWrapper
18+
return wrapper?.value as? T
19+
}
20+
21+
// unfortunately i was forced to start using such wrappers due to a new bug with structures hidden behind protocols
22+
internal class AssociationWrapper {
23+
let value: Any
24+
25+
init(value: Any) {
26+
self.value = value
27+
}
1828
}
1929

2030
extension Reactive where Base: AnyObject {

Diff for: Tests/ReusableViewTests.swift

+19
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,27 @@ class ReusableViewTests: XCTestCase {
154154
object.viewModel = "a"
155155
waitForExpectations(timeout: 1, handler: nil)
156156
}
157+
158+
func testViewModelStruct() {
159+
let reusable = TestReusable<TestStruct>()
160+
reusable.viewModel = TestStruct(value: "1")
161+
XCTAssertTrue(reusable.viewModel?.value == "1")
162+
}
163+
164+
func testViewModelStructErased() {
165+
let reusable = TestReusable<TestStructType>()
166+
reusable.viewModel = TestStruct(value: "1") as TestStructType
167+
XCTAssertTrue(reusable.viewModel?.value == "1")
168+
}
157169
}
158170

171+
fileprivate struct TestStruct: TestStructType {
172+
let value: String
173+
}
174+
175+
protocol TestStructType {
176+
var value: String { get }
177+
}
159178

160179
fileprivate class TestableNonEquatable {
161180
}

0 commit comments

Comments
 (0)