-
Notifications
You must be signed in to change notification settings - Fork 83
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
AttributeContainer extensions #58
Merged
eddiekaiger
merged 5 commits into
eddiekaiger:master
from
RomanPodymov:feature/attribute_container
Jun 2, 2023
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4e239f3
AttributeContainer extensions
RomanPodymov 609f002
Merge pull request #2 from eddiekaiger/master
RomanPodymov 7e5b440
Merge branch 'master' into feature/attribute_container
RomanPodymov 8f4a82d
Project file
RomanPodymov ccb4044
Formatting
RomanPodymov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
SwiftyAttributes/Sources/common/AttributeContainer+SwiftyAttributes.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// | ||
// AttributeContainer+SwiftyAttributes.swift | ||
// SwiftyAttributes | ||
// | ||
// Created by Roman Podymov on 29/04/23. | ||
// Copyright © 2023 Roman Podymov. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
#if canImport(UIKit) | ||
@available(iOS 15.0, tvOS 15.0, watchOS 8.0, *) | ||
public extension AttributeContainer { | ||
mutating func set(attribute: Attribute) { | ||
switch attribute { | ||
#if !os(watchOS) | ||
case .attachment(let value): | ||
self[AttributeScopes.UIKitAttributes.AttachmentAttribute.self] = value | ||
case .shadow(let value): | ||
self[AttributeScopes.UIKitAttributes.ShadowAttribute.self] = value | ||
#endif | ||
case .baselineOffset(let value): | ||
self[AttributeScopes.UIKitAttributes.BaselineOffsetAttribute.self] = value | ||
case .backgroundColor(let value): | ||
self[AttributeScopes.UIKitAttributes.BackgroundColorAttribute.self] = value | ||
case .expansion(let value): | ||
self[AttributeScopes.UIKitAttributes.ExpansionAttribute.self] = value | ||
case .font(let value): | ||
self[AttributeScopes.UIKitAttributes.FontAttribute.self] = value | ||
case .kern(let value): | ||
self[AttributeScopes.UIKitAttributes.KernAttribute.self] = value | ||
case .ligatures(let value): | ||
self[AttributeScopes.UIKitAttributes.LigatureAttribute.self] = value.rawValue | ||
case .link(let value): | ||
self[AttributeScopes.FoundationAttributes.LinkAttribute.self] = value | ||
case .obliqueness(let value): | ||
self[AttributeScopes.UIKitAttributes.ObliquenessAttribute.self] = value | ||
case .paragraphStyle(let value): | ||
self[AttributeScopes.UIKitAttributes.ParagraphStyleAttribute.self] = value | ||
case .strokeColor(let value): | ||
self[AttributeScopes.UIKitAttributes.StrokeColorAttribute.self] = value | ||
case .strokeWidth(let value): | ||
self[AttributeScopes.UIKitAttributes.StrokeWidthAttribute.self] = value | ||
case .strikethroughColor(let value): | ||
self[AttributeScopes.UIKitAttributes.StrikethroughColorAttribute.self] = value | ||
case .strikethroughStyle(let value): | ||
self[AttributeScopes.UIKitAttributes.StrikethroughStyleAttribute.self] = value | ||
case .textColor(let value): | ||
self[AttributeScopes.UIKitAttributes.ForegroundColorAttribute.self] = value | ||
case .textEffect(let value): | ||
self[AttributeScopes.UIKitAttributes.TextEffectAttribute.self] = value.textEffectStyle | ||
case .underlineColor(let value): | ||
self[AttributeScopes.UIKitAttributes.UnderlineColorAttribute.self] = value | ||
case .underlineStyle(let value): | ||
self[AttributeScopes.UIKitAttributes.UnderlineStyleAttribute.self] = value | ||
default: | ||
break | ||
} | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
SwiftyAttributesTests/AttributeContainer+SwiftyAttributes_Tests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// | ||
// AttributeContainer+SwiftyAttributes_Tests.swift | ||
// SwiftyAttributes | ||
// | ||
// Created by Roman Podymov on 29/04/23. | ||
// Copyright © 2023 Roman Podymov. All rights reserved. | ||
// | ||
|
||
import XCTest | ||
import SwiftyAttributes | ||
|
||
class AttributeContainer_SwiftyAttributes_Tests: XCTestCase { | ||
#if canImport(UIKit) | ||
@available(iOS 15.0, tvOS 15.0, watchOS 8.0, *) | ||
func testAttributeContainerSetAttribute() { | ||
var container = AttributeContainer() | ||
container.set(attribute: .textColor(.blue)) | ||
container.set(attribute: .backgroundColor(.yellow)) | ||
XCTAssertEqual(container.foregroundColor, UIColor.blue) | ||
XCTAssertEqual(container.backgroundColor, UIColor.yellow) | ||
} | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not necessary in this PR, but would be neat to also add a custom subscript to
set
andget
the attributesThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @eddiekaiger
Do you mean something like
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep!