Comments (4)
My guess is that it wasn't marked as public
because we didn't see a use case, but yours is definitely intriguing. @jvisenti should make the call, but this seems like a reasonable request to me.
from anchorage.
@rlwimi @ZevEisenberg I believe AnchorPair
is essentially an internal
type because exposing the initializer publicly could allow for unsafe usage of the API. Consider this function:
func == <T, U>(lhs: AnchorPair<T, U>, rhs: AnchorPair<T, U>) -> ConstraintPair
If you were to construct two AnchorPair<NSLayoutAnchor, NSLayoutAnchor>
, you could mix NSLayoutXAxisAnchor
and NSLayoutYAxisAnchor
however you wanted, which would result in a crash if you attempted to use this operator on mismatched types, i.e. trying to constraint an XAxisAnchor to a YAxisAnchor. The current API forbids this by construction.
That said, the existence of a valid use case may outweigh the pretty minor risk that comes with it. Happy to take a look at a PR if you have something put together already, and see how it could fit in.
from anchorage.
I was just reading through some code that I wrote in a project, and found what I believe is a valid use case:
var safeCenterAnchors: AnchorPair<NSLayoutXAxisAnchor, NSLayoutYAxisAnchor> {
if #available(iOS 11.0, *) {
return AnchorPair(first: safeAreaLayoutGuide.centerXAnchor, second: safeAreaLayoutGuide.centerYAnchor)
}
else {
return centerAnchors
}
}
from anchorage.
Thanks, everyone! Much appreciated.
from anchorage.
Related Issues (20)
- Prevent duplicate constraints. HOT 5
- Manual installation instructions HOT 2
- Relative alignment samples outdated HOT 2
- View could not display in full-screen size, black gap on top and also at bottom HOT 2
- Priority documentation not matching reality HOT 4
- Use of `BinaryFloatingPoint` types with custom operators. HOT 7
- Multi-binding syntax
- EXC_BAD_ACCESS switching from 4.0.0 to 4.1.0+ HOT 4
- Carthage prebuilt framework
- Order of operation when creating constraint HOT 5
- Update for Swift 5.0 HOT 4
- Add a shorthand for accessibilityIdentifier HOT 1
- Mark invalid combinations of anchors as deprecated HOT 1
- First time anchorage-usage confusing HOT 1
- Remove convenience accessors on UIViewController subclasses HOT 2
- Type-checking Performance HOT 10
- Add a logo
- Please Update for Swift 5.2 HOT 2
- Carthage problems on Xcode 12 HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from anchorage.