Skip to content
This repository was archived by the owner on Jan 15, 2026. It is now read-only.

Commit 971929b

Browse files
authored
Merge pull request #87 from iZettle/TextStyle_Equatable_BugFix
TextStyle Equatable bug fix
2 parents 7c5a45f + 566cbd0 commit 971929b

3 files changed

Lines changed: 36 additions & 1 deletion

File tree

Form.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
CA6755EA1D4B6F1C000662FF /* SegmentedControlStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = CA6755E91D4B6F1C000662FF /* SegmentedControlStyle.swift */; };
3636
CD49499B1C199520000176D3 /* (null) in Sources */ = {isa = PBXBuildFile; };
3737
CDD2A5211F42DE7500E2B78B /* HighlightedTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD2A5201F42DE7500E2B78B /* HighlightedTests.swift */; };
38+
CFD2FFE3221323BF002D4D36 /* TextStyleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CFD2FFE2221323BF002D4D36 /* TextStyleTests.swift */; };
3839
E63D89BF1DF59D6100AAB381 /* DisplayableString.swift in Sources */ = {isa = PBXBuildFile; fileRef = E63D89BE1DF59D6100AAB381 /* DisplayableString.swift */; };
3940
F60102311DAE2D410020015B /* TableChange.swift in Sources */ = {isa = PBXBuildFile; fileRef = F60102301DAE2D410020015B /* TableChange.swift */; };
4041
F604260A20B6A47E00BC4CAB /* ParentChildRelationalTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F604260920B6A47E00BC4CAB /* ParentChildRelationalTests.swift */; };
@@ -139,6 +140,7 @@
139140
B35F8B4B1F3783E400904E37 /* CollectionDiffTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CollectionDiffTests.swift; sourceTree = "<group>"; };
140141
CA6755E91D4B6F1C000662FF /* SegmentedControlStyle.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SegmentedControlStyle.swift; path = Form/SegmentedControlStyle.swift; sourceTree = "<group>"; };
141142
CDD2A5201F42DE7500E2B78B /* HighlightedTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HighlightedTests.swift; sourceTree = "<group>"; };
143+
CFD2FFE2221323BF002D4D36 /* TextStyleTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextStyleTests.swift; sourceTree = "<group>"; };
142144
E63D89BE1DF59D6100AAB381 /* DisplayableString.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = DisplayableString.swift; path = Form/DisplayableString.swift; sourceTree = SOURCE_ROOT; };
143145
F60102301DAE2D410020015B /* TableChange.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = TableChange.swift; path = Form/TableChange.swift; sourceTree = "<group>"; };
144146
F604260920B6A47E00BC4CAB /* ParentChildRelationalTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ParentChildRelationalTests.swift; sourceTree = "<group>"; };
@@ -263,6 +265,7 @@
263265
F62E45B51CABFB5300C6867E /* FormTests */ = {
264266
isa = PBXGroup;
265267
children = (
268+
CFD2FFE2221323BF002D4D36 /* TextStyleTests.swift */,
266269
CDD2A5201F42DE7500E2B78B /* HighlightedTests.swift */,
267270
1C2881821F20EE2000666A21 /* SelectViewTests.swift */,
268271
1CDD56A91D9C10D7004B0CA9 /* TableTests.swift */,
@@ -572,6 +575,7 @@
572575
isa = PBXSourcesBuildPhase;
573576
buildActionMask = 2147483647;
574577
files = (
578+
CFD2FFE3221323BF002D4D36 /* TextStyleTests.swift in Sources */,
575579
F604260A20B6A47E00BC4CAB /* ParentChildRelationalTests.swift in Sources */,
576580
F6B81B9420CA906000B6AC39 /* NumberEditorTests.swift in Sources */,
577581
CDD2A5211F42DE7500E2B78B /* HighlightedTests.swift in Sources */,

Form/TextStyle.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@ public extension TextStyle {
136136
var style = ((self.attribute(for: .paragraphStyle) as NSParagraphStyle?)?.mutableCopy() as? NSMutableParagraphStyle) ?? NSMutableParagraphStyle()
137137
update(&style)
138138
attributes[.paragraphStyle] = style
139+
140+
if equatableForAttribute[.paragraphStyle] == nil {
141+
equatableForAttribute[.paragraphStyle] = { $0 as! NSMutableParagraphStyle == $1 as! NSMutableParagraphStyle }
142+
}
143+
139144
}
140145

141146
/// Register a custom `transfrom` for `attribute`
@@ -159,7 +164,7 @@ extension TextStyle: Equatable {
159164
}
160165

161166
for (attribute, left) in lhs.attributes {
162-
guard let right = rhs.attributes[attribute], attribute != .paragraphStyle else {
167+
guard let right = rhs.attributes[attribute] else {
163168
return false
164169
}
165170

FormTests/TextStyleTests.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//
2+
// TextStyleTests.swift
3+
// FormTests
4+
//
5+
// Created by Mayur Deshmukh on 12/02/19.
6+
// Copyright © 2019 iZettle. All rights reserved.
7+
//
8+
9+
import XCTest
10+
import Form
11+
12+
class TextStyleTests: XCTestCase {
13+
14+
func testTextStyleEquality() {
15+
let textStyle1 = TextStyle(font: .systemFont(ofSize: 14.0), color: .red, alignment: .left, lineBreakMode: .byWordWrapping)
16+
let textStyle2 = TextStyle(font: .systemFont(ofSize: 14.0), color: .red, alignment: .left, lineBreakMode: .byWordWrapping)
17+
let textStyle3 = TextStyle(font: .systemFont(ofSize: 14.0), color: .red, alignment: .left, lineBreakMode: .byCharWrapping)
18+
let textStyle4 = TextStyle(font: .systemFont(ofSize: 15.0), color: .red, alignment: .left, lineBreakMode: .byWordWrapping)
19+
let textStyle5 = TextStyle(font: .systemFont(ofSize: 14.0), color: .green, alignment: .left, lineBreakMode: .byWordWrapping)
20+
21+
XCTAssertEqual(textStyle1, textStyle2)
22+
XCTAssertNotEqual(textStyle1, textStyle3)
23+
XCTAssertNotEqual(textStyle1, textStyle4)
24+
XCTAssertNotEqual(textStyle1, textStyle5)
25+
}
26+
}

0 commit comments

Comments
 (0)