BLACK FRIDAY SALE: Save big on all my Swift books and bundles! >>

Connect two ....addSubview(x,y)

Forums > Swift

Good day. how to connect two teams? I`m newbie

    let importClassUIImage = CreateCardCPU()
    let cardCPUOne = importClassUIImage.CreateCard(positionX: self.buttomStart.frame.minX, positionY: 200, tags: 1)
    let cardCPUTwo = importClassUIImage.CreateCard(positionX: self.buttomStart.frame.maxX, positionY: 200, tags: 2)

    ???self.view.addSubview(cardCPUOne, cardCPUTwo)???



Hello, can you clarify what are you trying to accomplish? What does this CreateCardCPU return?


And what do you mean by "connecting two teams"? Basically you already are adding both views cardCPUOne and cardCPUTwo as a subviews.


class CreateCardCPU { func CreateCard(positionX: CGFloat, positionY: CGFloat, tags: Int) -> UIImageView { var cardCPU = UIImageView() let myCardFrame = CGRect(x: 0, y: 0, width: 142, height: 200) cardCPU = UIImageView(frame: myCardFrame) cardCPU.image = UIImage(named: "back.png") = positionX = positionY cardCPU.tag = tags return cardCPU } }

I thought that you can call two pictures. I wanted to optimize the code



[cardCPUOne, cardCPUTwo].forEach { view.addSubview($0) }
// Put constraints for each view here


Thanks. Very grateful.



Hacking with Swift is sponsored by RevenueCat

SPONSORED In-app subscriptions are a pain to implement, hard to test, and full of edge cases. RevenueCat makes it straightforward and reliable so you can get back to building your app. Oh, and it's free if your app makes less than $10k/mo.

Learn more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.