-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from p-x9/feature/non-apple-platform
Support for non-apple platform
- Loading branch information
Showing
12 changed files
with
452 additions
and
303 deletions.
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
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
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
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
43 changes: 43 additions & 0 deletions
43
Sources/AssociatedObject/Extension/swift_AssociationPolicy+.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,43 @@ | ||
// | ||
// swift_AssociationPolicy+.swift | ||
// | ||
// | ||
// Created by p-x9 on 2024/01/29. | ||
// | ||
// | ||
|
||
#if canImport(ObjectAssociation) | ||
|
||
import ObjectAssociation | ||
|
||
/// Extension for swift_AssociationPolicy to provide a more Swift-friendly interface. | ||
extension swift_AssociationPolicy { | ||
/// Represents the atomicity options for associated objects. | ||
public enum Atomicity { | ||
/// Indicates that the associated object should be stored atomically. | ||
case atomic | ||
/// Indicates that the associated object should be stored non-atomically. | ||
case nonatomic | ||
} | ||
|
||
/// A property wrapper that corresponds to `.SWIFT_ASSOCIATION_ASSIGN` policy. | ||
public static var assign: Self { .SWIFT_ASSOCIATION_ASSIGN } | ||
|
||
/// A property wrapper that corresponds to `.SWIFT_ASSOCIATION_WEAK` policy. | ||
public static var weak: Self { .SWIFT_ASSOCIATION_WEAK } | ||
|
||
/// Create an association policy for retaining an associated object with the specified atomicity. | ||
/// | ||
/// - Parameter atomicity: The desired atomicity for the associated object. | ||
/// - Returns: The appropriate association policy for retaining with the specified atomicity. | ||
public static func retain(_ atomicity: Atomicity) -> Self { | ||
switch atomicity { | ||
case .atomic: | ||
return .SWIFT_ASSOCIATION_RETAIN | ||
case .nonatomic: | ||
return .SWIFT_ASSOCIATION_RETAIN_NONATOMIC | ||
} | ||
} | ||
} | ||
|
||
#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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// | ||
// functions.swift | ||
// | ||
// | ||
// Created by p-x9 on 2024/01/28. | ||
// | ||
// | ||
|
||
#if canImport(ObjectiveC) | ||
import ObjectiveC | ||
#elseif canImport(ObjectAssociation) | ||
import ObjectAssociation | ||
#else | ||
#warning("Current platform is not supported") | ||
#endif | ||
|
||
|
||
public func getAssociatedObject( | ||
_ object: AnyObject, | ||
_ key: UnsafeRawPointer | ||
) -> Any? { | ||
#if canImport(ObjectiveC) | ||
objc_getAssociatedObject(object, key) | ||
#elseif canImport(ObjectAssociation) | ||
ObjectAssociation.getAssociatedObject(object, key) | ||
#endif | ||
} | ||
|
||
|
||
public func setAssociatedObject( | ||
_ object: AnyObject, | ||
_ key: UnsafeRawPointer, | ||
_ value: Any?, | ||
_ policy: Policy = .retain(.nonatomic) | ||
) { | ||
#if canImport(ObjectiveC) | ||
objc_setAssociatedObject( | ||
object, | ||
key, | ||
value, | ||
policy | ||
) | ||
#elseif canImport(ObjectAssociation) | ||
ObjectAssociation.setAssociatedObject( | ||
object, | ||
key, | ||
value | ||
) | ||
#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
Oops, something went wrong.