Home Blog Page 3834

UICollectionView knowledge supply and delegates programmatically



· 1 min learn


On this fast UIKit tutorial I am going to present you learn how to create a easy UICollectionView with out Interface Builder, however solely utilizing Swift.

UICollectionViewCell programmatically

For those who’d like so as to add views to your cell, it’s best to use the init(body:) technique, and arrange your view hierarchy there. As an alternative of awakeFromNib it’s best to type your views within the init technique as properly. You’ll be able to reset all the things inside the standard prepareForReuse technique. As you may see by utilizing anchors generally it’s price to ditch IB fully. 🎉

class Cell: UICollectionViewCell {

    static var identifier: String = "Cell"

    weak var textLabel: UILabel!

    override init(body: CGRect) {
        tremendous.init(body: body)

        let textLabel = UILabel(body: .zero)
        textLabel.translatesAutoresizingMaskIntoConstraints = false
        contentView.addSubview(textLabel)
        NSLayoutConstraint.activate([
            contentView.centerXAnchor.constraint(equalTo: textLabel.centerXAnchor),
            contentView.centerYAnchor.constraint(equalTo: textLabel.centerYAnchor),
        ])
        self.textLabel = textLabel
        reset()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been carried out")
    }

    override func prepareForReuse() {
        tremendous.prepareForReuse()
        
        reset()
    }

    func reset() {
        textLabel.textAlignment = .heart
    }
}

UICollectionView programmatically

Creating assortment view controllers utilizing solely Swift code requires just a few extra strains. You’ll be able to implement loadView and create your UICollectionView object there. Retailer a weak reference of it contained in the controller, and the remaining is identical.

class ViewController: UIViewController {

    weak var collectionView: UICollectionView!

    var knowledge: [Int] = Array(0..<10)

    override func loadView() {
        tremendous.loadView()

        let collectionView = UICollectionView(
            body: .zero, 
            collectionViewLayout: UICollectionViewFlowLayout()
        )
        collectionView.translatesAutoresizingMaskIntoConstraints = false
        view.addSubview(collectionView)
        NSLayoutConstraint.activate([
            view.topAnchor.constraint(equalTo: collectionView.topAnchor),
            view.bottomAnchor.constraint(equalTo: collectionView.bottomAnchor),
            view.leadingAnchor.constraint(equalTo: collectionView.leadingAnchor),
            view.trailingAnchor.constraint(equalTo: collectionView.trailingAnchor),
        ])
        collectionView = collectionView
    }

    override func viewDidLoad() {
        tremendous.viewDidLoad()

        collectionView.dataSource = self
        collectionView.delegate = self
        collectionView.register(Cell.self, forCellWithReuseIdentifier: Cell.identifier)
        collectionView.alwaysBounceVertical = true
        collectionView.backgroundColor = .white
    }
}

extension ViewController: UICollectionViewDataSource {

    func collectionView(
        _ collectionView: UICollectionView,
        numberOfItemsInSection part: Int
    ) -> Int {
        knowledge.depend
    }

    func collectionView(
        _ collectionView: UICollectionView,
        cellForItemAt indexPath: IndexPath
    ) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(
            withReuseIdentifier: Cell.identifier, 
            for: indexPath
        ) as! Cell

        let knowledge = knowledge[indexPath.item]
        cell.textLabel.textual content = String(knowledge)
        return cell
    }
}

extension ViewController: UICollectionViewDelegate {

    func collectionView(
        _ collectionView: UICollectionView, 
        didSelectItemAt indexPath: IndexPath
    ) {

    }
}

extension ViewController: UICollectionViewDelegateFlowLayout {

    func collectionView(
        _ collectionView: UICollectionView,
        structure collectionViewLayout: UICollectionViewLayout,
        sizeForItemAt indexPath: IndexPath
    ) -> CGSize {
        .init(width: collectionView.bounds.width, peak: 44)
    }

    func collectionView(
        _ collectionView: UICollectionView,
        structure collectionViewLayout: UICollectionViewLayout,
        insetForSectionAt part: Int
    ) -> UIEdgeInsets {
        .init(prime: 0, left: 0, backside: 0, proper: 0) //.zero
    }

    func collectionView(
        _ collectionView: UICollectionView,
        structure collectionViewLayout: UICollectionViewLayout,
        minimumInteritemSpacingForSectionAt part: Int
    ) -> CGFloat {
        0
    }

    func collectionView(
        _ collectionView: UICollectionView,
        structure collectionViewLayout: UICollectionViewLayout,
        minimumLineSpacingForSectionAt part: Int
    ) -> CGFloat {
        0
    }
}

That was straightforward. Anchors are actually highly effective, Interface Builder is extraordinarily useful, however generally it’s simply quicker to create your views from code. The selection is yours, however please don’t be afraid of coding consumer interfaces! 😅

Associated posts


On this article I’ve gathered my prime 10 favourite fashionable UIKit ideas that I might positively need to know earlier than I begin my subsequent venture.


Discover ways to construct advanced kinds with my up to date assortment view view-model framework with out the battle utilizing Swift.


Do you need to discover ways to load a xib file to create a customized view object? Effectively, this UIKit tutorial is only for you written in Swift.


Just a bit recommendation about creating customized view programmatically and the reality about why type constructing with assortment views sucks.

Attackers Exploit Public .env Information to Breach Cloud Accounts in Extortion Marketing campaign

0


Aug 16, 2024Ravie LakshmananCloud Safety / Utility Safety

Attackers Exploit Public .env Information to Breach Cloud Accounts in Extortion Marketing campaign

A big-scale extortion marketing campaign has compromised numerous organizations by profiting from publicly accessible atmosphere variable recordsdata (.env) that comprise credentials related to cloud and social media purposes.

“A number of safety missteps had been current in the middle of this marketing campaign, together with the next: Exposing atmosphere variables, utilizing long-lived credentials, and absence of least privilege structure,” Palo Alto Networks Unit 42 mentioned in a Thursday report.

The marketing campaign is notable for organising its assault infrastructure inside the contaminated organizations’ Amazon Net Companies (AWS) environments and utilizing them as a launchpad for scanning greater than 230 million distinctive targets for delicate knowledge.

With 110,000 domains focused, the malicious exercise is alleged to have netted over 90,000 distinctive variables within the .env recordsdata, out of which 7,000 belonged to organizations’ cloud companies and 1,500 variables are linked to social media accounts.

Cybersecurity

“The marketing campaign concerned attackers efficiently ransoming knowledge hosted inside cloud storage containers,” Unit 42 mentioned. “The occasion didn’t embrace attackers encrypting the information earlier than ransom, however fairly they exfiltrated the information and positioned the ransom word within the compromised cloud storage container.”

Probably the most hanging side of the assaults is that it does not depend on safety vulnerabilities or misconfigurations in cloud suppliers’ companies, however fairly stems from the unintended publicity of .env recordsdata on unsecured net purposes to achieve preliminary entry.

A profitable breach of a cloud atmosphere utilizing stolen credentials paves the best way for intensive discovery and reconnaissance steps with an purpose to broaden their foothold, with the risk actors weaponizing AWS Identification and Entry Administration (IAM) entry keys to create new roles and escalate their privileges.

The brand new IAM function with administrative permissions is then used to create new AWS Lambda features to provoke an automatic internet-wide scanning operation containing hundreds of thousands of domains and IP addresses.

“The script retrieved an inventory of potential targets from a publicly accessible third-party S3 bucket exploited by the risk actor,” Unit 42 researchers Margaret Zimmermann, Sean Johnstone, William Gamazo, and Nathaniel Quist mentioned.

“The checklist of potential targets the malicious lambda operate iterated over contained a document of sufferer domains. For every area within the checklist, the code carried out a cURL request, concentrating on any atmosphere variable recordsdata uncovered at that area, (i.e., https:///.env).”

Ought to the goal area host an uncovered atmosphere file and the file comprise cleartext cloud credentials, they’re extracted and saved in a newly created folder inside one other risk actor-controlled public AWS S3 bucket. The bucket has since been taken down by AWS.

The assault marketing campaign has been discovered to particularly single out situations the place the .env recordsdata comprise Mailgun credentials, indicating an effort on the a part of the adversary to leverage them for sending phishing emails from authentic domains and bypass safety protections.

The an infection chain ends with the risk actor exfiltrating and deleting delicate knowledge from the sufferer’s S3 bucket, and importing a ransom word that urges them to contact and pay a ransom to keep away from promoting the knowledge on the darkish net.

The monetary motivations of the assault are additionally evident within the risk actor’s failed makes an attempt to create new Elastic Cloud Compute (EC2) sources for illicit cryptocurrency mining.

Cybersecurity

It is at present not clear who’s behind the marketing campaign, partly as a result of using VPNs and the TOR community to hide their true origin, though Unit 42 mentioned it detected two IP addresses that had been geolocated in Ukraine and Morocco as a part of the lambda operate and S3 exfiltration actions, respectively.

“The attackers behind this marketing campaign seemingly leveraged intensive automation strategies to function efficiently and quickly,” the researchers mentioned. “This means that these risk actor teams are each expert and educated in superior cloud architectural processes and strategies.”

Replace

Following the publication of the story, an AWS spokesperson shared the beneath assertion with The Hacker Information –

AWS companies and infrastructure aren’t affected by the findings of those researchers. The problems described on this weblog had been a results of a nasty actor abusing misconfigured net purposes — hosted each within the cloud and elsewhere — that allowed public entry to atmosphere variable (.env) recordsdata. A few of these recordsdata contained numerous sorts of credentials, together with AWS credentials which had been then utilized by the unhealthy actor to name AWS APIs. Surroundings variable recordsdata ought to by no means be publicly uncovered, and even when stored personal, ought to by no means comprise AWS credentials. AWS gives quite a lot of easy-to-use mechanisms for net purposes to entry momentary AWS credentials in a safe style. We advocate prospects observe finest practices for AWS Identification and Entry Administration (IAM) to assist safe their AWS sources.

(The story was up to date after publication to incorporate a response from AWS and make clear that the breach requires extracting the cloud credentials from the .env recordsdata.)

Discovered this text attention-grabbing? Comply with us on Twitter and LinkedIn to learn extra unique content material we publish.



Ballot end result: Years later, you are still having points with RCS messaging

0


RCS on iMessage sending image

Ryan Haines / Android Authority

Wealthy Communication Providers, or RCS, is a messaging protocol now utilized by many throughout the US and the globe, nevertheless it wasn’t all the time the case. It took ages to realize momentum after its conception in 2007. Nonetheless, regardless of its accelerated adoption, the protocol nonetheless isn’t fairly as ubiquitous as SMS.

That is particularly obvious when utilizing the protocol to speak with these on Apple units. iPhones require RCS customers to be tied to a supported provider, leaving many who get pleasure from cheaper pay as you go plans out within the chilly. The truth that Apple solely lately adopted RCS additionally put a spanner within the works.

Contemplating all this, we requested customers if they’d skilled any issues with RCS messaging. Listed here are the outcomes from the ballot.

RCS stays a problematic protocol

RCS on iMessage top of chat

Ryan Haines / Android Authority

Most (46.4%) of the practically 2,200 voters observe that RCS “all the time works positive,” suggesting that the protocol is generally fuss-free. 38.1% declare that “it really works” however not with all contacts, whereas just below 11% don’t use it in any respect. Solely 4.5% of respondents observe that RCS has by no means labored for them.

Many within the feedback blame Apple for the fragmentation. “I want Apple would’ve simply executed RCS 5 years in the past when everybody else began utilizing it. However Tim “purchase your mom an iPhone” Cook dinner was extra considering gross sales than making the iPhone usable in a market not fully monopolized by Apple,” writes one reader.

It must be famous that our ballot was run on an article discussing the troubled RCS relationship between Android and iPhones; naturally, there’ll be some anti-Apple sentiment.

Apparently, customers past the US recommend that RCS stays secondary to different protocols and platforms. “I imply, truthfully, everybody I do know is on WhatsApp — besides for kids who’re too younger for the TOS. My 8-year-old makes use of RCS for members of the family beneath supervision, none of whom use an iPhone. I do know 50% of the inhabitants use iOS within the UK, however I do not know who they really are!”

There’s clearly a divide between platforms, apps, carriers, and areas that RCS might want to bridge earlier than it turns into as seamless as its predecessors. If it’ll ever obtain this stays to be seen.

New AirPods Professional 2 beta firmware obtainable now with iOS 18 options

0


Should you’ve received a pair of AirPods Professional 2 and a developer account, you are going to have a brand new firmware replace to get pleasure from.

Apple has launched a brand new beta firmware replace for AirPods Professional 2. Firmware model 7A5290a replaces model 7A5266c and is on the market for each the USB-C and Lightning variations of the wi-fi earbuds so long as you are operating the beta as a developer.



Get Superior Advert Blocking and Superior Knowledge Privateness Instruments for $11


TL;DR: Do away with annoying adverts whereas defending your privateness and confidential knowledge with a lifetime subscription to AdGuard — new customers can get it for simply $11 at TechRepublic Academy.

With a lot enterprise being transacted on-line and a lot of our knowledge being saved within the cloud, sustaining privateness and safety are extra necessary than ever. Plus, these irritating banner and popup adverts could be extra than simply an annoyance. A few of them are literally only a entrance for severely harmful malware. Happily, now you can block adverts and shield your self on-line with a lifetime subscription to AdGuard.

About AdGuard

Not solely will AdGuard banish annoying popups, video adverts and banners with superior advert blocking, however additionally, you will get superior knowledge privateness instruments. This system is powered by superior digital and computing know-how to maintain you shielded in our on-line world.

AdGuard offers the last word privateness safety so that you now not must worry the multitude of exercise trackers and analyzers which can be everywhere in the net. Superior safety from malware can also be included. So all your most confidential knowledge might be protected from phishing makes an attempt, fraudulent web sites and different assaults.

You additionally get strong parental management that permits you to create a protected digital atmosphere by limiting your youngsters’s entry to any grownup or inappropriate content material. AdGuard could be put in on as much as three units and is appropriate throughout a number of working techniques, together with Home windows, Android and iOS. So you’ll be able to entry it on desktops and cell units.

It’s straightforward to see why AdGuard has an distinctive consumer score of 4.7 out of 5 stars on Trustpilot. Better of all, since it is a lifetime subscription, you get all these unbelievable options perpetually for only one low fee.

Select your plan and get a lifetime subscription to AdGuard whereas the value has been dropped for brand spanking new customers for a restricted time:

Additionally in search of a VPN? Try AdGuard plans obtainable at TechRepublic Academy:

You can too discover extra nice offers in our collection of Privateness and Safety merchandise.

Costs and availability are topic to alter.