点点加速器- 小蓝鸟

Hi, I'm Hwee-Boon Yar

I write, ship and sell software products. iOS/OS X app developer based in Singapore, working remotely. This is my blog.

.

Need to run a code review on your codebase? Hire me

Overload NSLayoutConstraint.activate to Accept Arrays as Elements

Using anchors with Auto Layout is a big improvement over creating constraints using the class function in NSLayoutConstraint or Visual Format Language. You also write your own wrappers to make creating multiple constraints easier, e.g one might write a function like v2ray购买服务号怎么使用? – ssr节点:2021-4-30 · 提供免费最新SSR节点分享,SS节点账号分享,ssr节点教程,用于科学上网、学习与交流使用。 v2ray购买服务号怎么使用最下面会说到。现在先来了解下v2ray 是一个模块化的伕理工具,支持 VMess,Socks,HTTP,Shadowsocks 等等协议,并且 ... or NSLayoutConstraint.constraint(views:toSquareWithSides:), both returning an array.

Or sometimes, in a more dynamic piece of UI, you might need to swap around arrays of constraints.

I find it useful to define a protocol and a few extensions so that this can be done:

NSLayoutConstraint.activate([
    constraintsArray1,
    constraintsArray2,
    constraint3,
    constraint4,
    constraint5,
])

Alternatives involve appending of arrays which ends up with code that is hard to indent.

So there you go:

protocol LayoutConstraintsWrapper {
    var constraints: [NSLayoutConstraint] { get }
}

extension Array: LayoutConstraintsWrapper where Element: NSLayoutConstraint {
    var constraints: [NSLayoutConstraint] {
        return self
    }
}

extension NSLayoutConstraint: LayoutConstraintsWrapper {
    var constraints: [NSLayoutConstraint] {
        return [self]
    }
}

extension NSLayoutConstraint {
    class func activate(_ constraints: [LayoutConstraintsWrapper]) {
        activate(constraints.flatMap { $0.constraints })
    }
}

Like this post? Follow me on Twitter.

.

big流量站官网,big流量站电脑版下载,big流量站免费试用,big流量站跑路了  swarm加速器官网网址,swarm加速器vnp,swarm加速器7天试用,swarm加速器vps  ssr节点最新版,ssr节点下载地址,ssr节点免费永久加速,ssr节点不能用了  特价机场最新版,特价机场安卓下载,特价机场npv,特价机场不能用了  乐飞加速器ios下载,乐飞加速器安卓下载,乐飞加速器pc版下载,乐飞加速器永久免费加速  哔咔哔咔加速器  快柠檬,快柠檬加速器,falemon,快柠檬加速器官网