10.4 C
New York
Thursday, April 10, 2025
Home Blog Page 3878

Fixing “Seize of non-sendable sort in @Sendable closure” in Swift


Revealed on: August 7, 2024

When you begin migrating to the Swift 6 language mode, you will probably activate strict concurrency first. As soon as you’ve got executed this there can be a number of warings and errors that you will encounter and these errors might be complicated at occasions.

I will begin by saying that having a strong understanding of actors, sendable, and knowledge races is a big benefit while you wish to undertake the Swift 6 language mode. Just about all the warnings you will get in strict concurrency mode will inform you about potential points associated to operating code concurrently. For an in-depth understanding of actors, sendability and knowledge races I extremely advocate that you simply check out my Swift Concurrency course which can get you entry to a collection of movies, workouts, and my Sensible Swift Concurrency ebook with a single buy.

WIth that out of the best way, let’s check out the next warning that you simply would possibly encounter in your mission:

Seize of non-sendable sort in @Sendable closure

This warning tells us that we’re capturing and utilizing a property inside a closure. This closure is marked as @Sendable which implies that we should always count on this closure to run in a concurrent setting. The Swift compiler warns us that, as a result of this closure will run concurrently, we should always be sure that any properties that we seize inside this closure can safely be used from concurrent code.

In different phrases, the compiler is telling us that we’re risking crashes as a result of we’re passing an object that may’t be used from a number of duties to a closure that we should always count on to be run from a number of duties. Or at the very least we should always count on our closure to be transferred from one activity to a different.

In fact, there is not any ensures that our code will crash. Neither is it assured that our closure can be run from a number of locations on the similar time. What issues right here is that the closure is marked as @Sendable which tells us that we should always be sure that something that is captured inside the closure can be Sendable.

For a fast overview of Sendability, take a look at my publish on the subject right here.

An instance of the place this warning would possibly happen might appear like this:

func run(accomplished: @escaping TaskCompletion) {
    guard !metaData.isFinished else {
        DispatchQueue.primary.async {
            // Seize of 'accomplished' with non-sendable sort 'TaskCompletion' (aka '(End result, any Error>) -> ()') in a `@Sendable` closure; that is an error within the Swift 6 language mode
            // Sending 'accomplished' dangers inflicting knowledge races; that is an error within the Swift 6 language mode
            accomplished(.failure(TUSClientError.uploadIsAlreadyFinished))
        }
        return
    }

    // ...
}

The compiler is telling us that the accomplished closure that we’re receiving within the run perform cannot be handed toDispatchQueue.primary.async safely. The explanation for that is that the run perform is assumed to be run in a single isolation context, and the closure handed to DispatchQueue.primary.async will run in one other isolation context. Or, in different phrases, run and DispatchQueue.primary.async would possibly run as a part of completely different duties or as a part of completely different actors.

To repair this, we’d like. to be sure that our TaskCompletion closure is @Sendable so the compiler is aware of that we are able to safely move that closure throughout concurrency boundaries:

// earlier than
typealias TaskCompletion = (End result<[ScheduledTask], Error>) -> ()

// after
typealias TaskCompletion = @Sendable (End result<[ScheduledTask], Error>) -> ()

In most apps, a repair like it will introduce new warnings of the identical variety. The explanation for that is that as a result of the TaskCompletion closure is now @Sendable, the compiler goes to be sure that each closure handed to our run perform would not captuire any non-sendable varieties.

For instance, one of many locations the place I name this run perform would possibly appear like this:

activity.run { [weak self] end in
    // Seize of 'self' with non-sendable sort 'Scheduler?' in a `@Sendable` closure; that is an error within the Swift 6 language mode
    guard let self = self else { return }
    // ...
}

As a result of the closure handed to activity.run must be @Sendable any captured varieties additionally must be made Sendable.

At this level you will usually discover that your refactor is snowballing into one thing a lot larger.

On this case, I have to make Scheduler conform to Sendable and there is two methods for me to try this:

  • Conform Scheduler to Sendable
  • Make Scheduler into an actor

The second choice is probably the best choice. Making Scheduler an actor would permit me to have mutable state with out knowledge races on account of actor isolation. Making the Scheduler conform to Sendable with out making it an actor would imply that I’ve to do away with all mutable state since lessons with mutable state cannot be made Sendable.

Utilizing an actor would imply that I can not instantly entry a variety of the state and capabilities on that actor. It would be required to start out awaiting entry which implies that a variety of my code has to develop into async and wrapped in Activity objects. The refactor would get uncontrolled actual quick that means.

To restrict the scope of my refactor it is smart to introduce a 3rd, short-term choice:

  • Conform Scheduler to Sendable utilizing the unchecked attribute

For this particular case I take note of, I do know that Scheduler was written to be thread-safe. Because of this it’s very secure to work with Scheduler from a number of duties, threads, and queues. Nevertheless, this security was carried out utilizing outdated mechanisms like DispatchQueue. In consequence, the compiler will not simply settle for my declare that Scheduler is Sendable.

By making use of @unchecked Sendable on this class the compiler will settle for that Scheduler is Sendable and I can proceed my refactor.

As soon as I am able to convert Scheduler to an actor I can take away the @unchecked Sendable, change my class to an actor and proceed updating my code and resolving warnings. That is nice as a result of it means I haven’t got to leap down rabbit gap after rabbit gap which might end in a refactor that will get means out of hand and turns into nearly not possible to handle appropriately.

Cross-Platform, Cli App To Carry out Varied Operations On String

0




Cross-Platform, Cli App To Carry out Varied Operations On String

sttr is command line software program that permits you to rapidly run numerous transformation operations on the string.

// With enter immediate
sttr

// Direct enter
sttr md5 "Good day World"

// File enter
sttr md5 file.textual content
sttr base64-encode picture.jpg

// Studying from completely different processor like cat, curl, printf and so forth..
echo "Good day World" | sttr md5
cat file.txt | sttr md5

// Writing output to a file
sttr yaml-json file.yaml > file-output.json

Fast set up

You may run the beneath curl to put in it someplace in your PATH for straightforward use. Ideally will probably be put in at ./bin folder

curl -sfL https://uncooked.githubusercontent.com/abhimanyu003/sttr/fundamental/set up.sh | sh

Webi

MacOS / Linux

curl -sS https://webi.sh/sttr | sh

Home windows

curl.exe https://webi.ms/sttr | powershell

See right here

Homebrew

If you’re on macOS and utilizing Homebrew, you’ll be able to set up sttr with the next:

brew faucet abhimanyu003/sttr
brew set up sttr

Snap

sudo snap set up sttr

Arch Linux

yay -S sttr-bin

Scoop

scoop bucket add sttr https://github.com/abhimanyu003/scoop-bucket.git
scoop set up sttr

Go

go set up github.com/abhimanyu003/sttr@newest

Manually

Obtain the pre-compiled binaries from the Launch! web page and duplicate them to the specified location.

  • After set up merely run sttr command.
// For interactive menu
sttr
// Present your enter
// Press two enter to open operation menu
// Press `/` to filter numerous operations.
// May also press UP-Down arrows choose numerous operations.
sttr -h

// Instance
sttr zeropad -h
sttr md5 -h

  • Working with information enter.
sttr {command-name} {filename}

sttr base64-encode picture.jpg
sttr md5 file.txt
sttr md-html Readme.md

sttr yaml-json file.yaml > file-output.json
  • Taking enter from different command.
curl https: //jsonplaceholder.typicode.com/customers | sttr json-yaml
  • Chaining the completely different processor.
sttr md5 hi there | sttr base64-encode

echo "Good day World" | sttr base64-encode | sttr md5

Encode/Decode

  • [x] ascii85-encode – Encode your textual content to ascii85
  • [x] ascii85-decode – Decode your ascii85 textual content
  • [x] base32-decode – Decode your base32 textual content
  • [x] base32-encode – Encode your textual content to base32
  • [x] base64-decode – Decode your base64 textual content
  • [x] base64-encode – Encode your textual content to base64
  • [x] base85-encode – Encode your textual content to base85
  • [x] base85-decode – Decode your base85 textual content
  • [x] base64url-decode – Decode your base64 url
  • [x] base64url-encode – Encode your textual content to url
  • [x] html-decode – Unescape your HTML
  • [x] html-encode – Escape your HTML
  • [x] rot13-encode – Encode your textual content to ROT13
  • [x] url-decode – Decode URL entities
  • [x] url-encode – Encode URL entities

Hash

  • [x] bcrypt – Get the Bcrypt hash of your textual content
  • [x] md5 – Get the MD5 checksum of your textual content
  • [x] sha1 – Get the SHA1 checksum of your textual content
  • [x] sha256 – Get the SHA256 checksum of your textual content
  • [x] sha512 – Get the SHA512 checksum of your textual content

String

  • [x] camel – Rework your textual content to CamelCase
  • [x] kebab – Rework your textual content to kebab-case
  • [x] decrease – Rework your textual content to decrease case
  • [x] reverse – Reverse Textual content ( txeT esreveR )
  • [x] slug – Rework your textual content to slug-case
  • [x] snake – Rework your textual content to snake_case
  • [x] title – Rework your textual content to Title Case
  • [x] higher – Rework your textual content to UPPER CASE

Traces

  • [x] count-lines – Rely the variety of traces in your textual content
  • [x] reverse-lines – Reverse traces
  • [x] shuffle-lines – Shuffle traces randomly
  • [x] sort-lines – Type traces alphabetically
  • [x] unique-lines – Get distinctive traces from listing

Areas

  • [x] remove-spaces – Take away all areas + new traces
  • [x] remove-newlines – Take away all new traces

Rely

  • [x] count-chars – Discover the size of your textual content (together with areas)
  • [x] count-lines – Rely the variety of traces in your textual content
  • [x] count-words – Rely the variety of phrases in your textual content

RGB/Hex

  • [x] hex-rgb – Convert a #hex-color code to RGB
  • [x] hex-encode – Encode your textual content Hex
  • [x] hex-decode – Convert Hexadecimal to String

JSON

  • [x] json – Format your textual content as JSON
  • [x] json-escape – JSON Escape
  • [x] json-unescape – JSON Unescape
  • [x] json-yaml – Convert JSON to YAML textual content
  • [x] json-msgpack – Convert JSON to MSGPACK
  • [x] msgpack-json – Convert MSGPACK to JSON

YAML

  • [x] yaml-json – Convert YAML to JSON textual content

Markdown

  • [x] markdown-html – Convert Markdown to HTML

Extract

  • [x] extract-emails – Extract emails from given textual content
  • [x] extract-ip – Extract IPv4 and IPv6 out of your textual content
  • [x] extract-urls – Extract URls your textual content ( we do not do ping verify )

Different

  • [x] escape-quotes – escape single and double quotes out of your textual content
  • [x] completion – generate the autocompletion script for the required shell
  • [x] interactive – Use sttr in interactive mode
  • [x] model – Print the model of sttr
  • [x] zeropad – Pad a quantity with zeros
  • [x] and including extra….

These are the few places the place sttr was highlighted, many due to all of you. Please be happy so as to add any blogs/movies you could have made that debate sttr to the listing.



Barack Obama DNC 2024 speech: What it was actually about

0


Throughout his 2024 Democratic Nationwide Conference handle on Tuesday evening, former President Barack Obama made no secret of his disdain for Donald Trump. However his speech was greater than only a partisan broadside: It was a philosophical temporary in protection of liberalism, a form of first-principles ethical argument that no different main conference speaker provided.

Liberal, on this context, doesn’t seek advice from the time period’s use in partisan American politics. It refers as an alternative to the centuries-old philosophical custom that sees politics as essentially oriented across the values of freedom and equality. Authorities, for liberals, exists to allow folks to stay based on their very own imaginative and prescient for his or her lives; it has no enterprise telling folks what god to worship or giving sure teams of individuals extra rights than others.

Obama was a totally liberal president, and Trump a totally intolerant one. This clearly troubled Obama — troubled him a lot, in actual fact, that he devoted this most high-profile speech to explaining why Trump have to be defeated not simply politically but additionally philosophically.

The stakes of 2024, based on Barack Obama

Obama is hardly the primary individual to declare Trump a mortal enemy of liberalism. Ever since 2016, there’s been a library’s price of books printed on liberalism’s Trump-induced disaster and the way it should be resolved.

A few of Obama’s remarks adopted this literature relatively intently. Like many, Obama sees Trump’s divisive political type versus liberalism’s core precept of equality: that every one residents need to be handled equally, every free to pursue a great life in the way in which they see match (so long as they don’t damage others in doing so).

Trump, Obama says, attracts an elemental distinction “between the true People, who in fact assist [Trump], and the outsiders who don’t.” And that Trump and his allies imagine “one group’s achieve is one other group’s loss,” and that “freedom means the highly effective can do just about no matter they please.”

This, Obama says, is unsuitable. It’s unsuitable not only for Democrats and progressives, however for People — residents of a rustic whose very existence grew out of liberal thought. The Harris marketing campaign, in his telling, is tapping right into a elementary liberal impulse that permeates the American physique politic.

“The overwhelming majority of us don’t need to stay in a rustic that’s bitter and divided,” Obama stated. “We wish one thing that’s higher. We need to be higher. And the enjoyment and pleasure surrounding this marketing campaign tells us that we’re not alone.”

Dwelling this liberal imaginative and prescient, for Obama, means accepting the range inherent to a big society made up of individuals with all kinds of beliefs and worldviews: recognizing that “our fellow residents deserve the identical grace we hope they’ll lengthen to us.” It means understanding “true freedom” as one thing that provides all of us the precise “to make choices about our personal life [and] requires us to acknowledge that different folks have the precise to make choices which can be completely different than ours.” And it means seeing democracy as greater than “only a bunch of summary ideas and a bunch of dusty legal guidelines in a e-book someplace,” however relatively “the values we stay by.”

This, to be clear, shouldn’t be a case that Trump is un-American and thus will certainly lose: Obama took nice pains to emphasise that the race was nonetheless shut and will go both means. Somewhat, Obama is saying that what Trump stands for contradicts lots of the values that People declare to carry expensive — our core sense of what our nation is about and what it stands for. That America’s truest identification is liberal, and that this identification can transcend these issues that divide us.

I need to agree with that. However as I argue in my current e-book, there’s a deeply intolerant pressure in American politics — an ideology born out of the important contradiction between America’s state liberal beliefs and the truth of chattel slavery at its founding.

This custom, like Trump, rejects core liberal-democratic beliefs about equality. It’s no extra and no much less American than our loftier said beliefs; each symbolize genuine features of America’s identification, and each have triumphed at completely different instances all through our nation’s historical past.

The query, then, shouldn’t be whether or not American liberalism can reassert its naturally dominant place. It’s whether or not the America that Obama believes in will triumph on this spherical of a centuries-old battle towards an authoritarian twin.

Apple, Main League Baseball announce September “Friday Evening Baseball” schedule

0



Report Highlights Rising Dangers in Delicate Knowledge Administration


The quantity of delicate knowledge that corporations are harbouring in non-production environments, like improvement, testing, analytics, and AI/ML, is rising, based on a brand new report. Executives are additionally getting extra involved about defending it — and feeding it into new AI merchandise is just not serving to.

The “Delphix 2024 State of Knowledge Compliance and Safety Report” discovered that 74% of organisations that deal with delicate knowledge elevated the quantity stored in non-production, also referred to as decrease, environments within the final yr. What’s extra, 91% are anxious about their expanded publicity footprint because of this, placing them prone to breaches and non-compliance penalties.

The quantity of client knowledge that corporations maintain is rising general as a result of progress within the variety of on-line customers and their ongoing digital transformation efforts. The IDC forecasts that by 2025, the worldwide datasphere will develop to 163 zettabytes, ten occasions the 16.1 zettabytes of information generated in 2016.

In consequence, the quantity of delicate knowledge, akin to private identifiable data, protected well being data, and monetary particulars, being saved can also be growing.

Delicate knowledge is usually created and saved in manufacturing, or dwell, environments just like the CRM or ERP, which have tight controls and restricted entry. Nevertheless, customary IT operations typically end in knowledge being copied a number of occasions into non-production environments, permitting extra personnel entry and growing the danger of breach.

The report’s findings have been the results of a survey of 250 senior-level workers at organisations with a minimum of 5,000 workers that deal with delicate client knowledge. It was carried out by software program supplier Perforce.

SEE: Nationwide Public Knowledge Breach: 2.7bn Data Leaked on Darkish Net

Over half of companies have already skilled a knowledge breach

Over half of respondents mentioned they’d already skilled a breach of delicate knowledge stored in non-production environments.

Different proof helps that the problem is worsening: a examine by Apple discovered that there was a 20% enhance in knowledge breaches from 2022 to 2023. Certainly, 61% of Individuals have discovered their private knowledge had been breached or compromised sooner or later.

The Perforce report discovered that 42% of the respondent organisations have skilled ransomware. This malware, particularly, is a rising menace globally; a examine from Malwarebytes printed this month discovered that international ransomware assaults elevated by 33% within the final yr.

A part of the issue is that international provide chains have gotten longer and extra complicated, growing the variety of potential entry factors for attackers. A report from the Identification Theft Useful resource Middle discovered that the variety of organisations impacted by provide chain assaults surged by greater than 2,600 proportion factors between 2018 and 2023. Moreover, payouts exceeded $1 billion (£790 million) for the primary time in 2023, making it an more and more profitable exploit for attackers.

AI is the most important wrongdoer in relation to insecure client knowledge

With corporations now adopting AI into enterprise processes, it’s turning into more and more troublesome to maintain management of what knowledge goes the place.

AI techniques typically require using delicate client knowledge for coaching and operation, and the complexity of the algorithms and potential integration with exterior techniques can create new assault vectors which are laborious to handle. In truth, the report discovered that AI and ML are the main causes of delicate knowledge progress in non-production environments, as cited by 60% of respondents.

“AI environments could also be much less ruled and guarded than manufacturing environments,” the report’s authors wrote. “In consequence, they are often simpler to compromise.”

Enterprise decision-makers are conscious of this danger: 85% report considerations about regulatory non-compliance in AI environments. Whereas many AI-specific rules are of their infancy, GDPR requires private knowledge utilized in AI techniques to be processed lawfully and transparently, and there are numerous relevant state level-laws within the U.S..

SEE: AI Govt Order: White Home Releases 90-Day Progress Report

The E.U. AI Act got here into pressure in August, which units strict guidelines on using AI for facial recognition and safeguards for general-purpose AI techniques. Corporations that fail to adjust to the laws face fines starting from €35 million ($38 million USD) or 7% of worldwide turnover to €7.5 million ($8.1 million USD) or 1.5% of turnover, relying on the infringement and measurement of the corporate. It’s thought that extra related AI-specific rules will spring up in different areas within the close to future.

Different considerations about delicate knowledge in AI environments, cited by over 80% of the respondents to the Perforce examine, embody utilizing low high quality knowledge as enter into their AI fashions, private knowledge re-identification, and theft of mannequin coaching knowledge, which might embody IP and commerce secrets and techniques.

Companies are anxious in regards to the monetary value of insecure knowledge

One other foremost purpose giant companies are so involved about insecure knowledge is the prospect of a hefty non-compliance positive. Client knowledge is extensively topic to increasing rules, like GDPR and HIPAA, which may be complicated and alter incessantly.

Many rules, like GDPR, apply penalties based mostly on annual turnover, so greater corporations face greater fees. The Perforce report discovered that 43% of respondents have already needed to pay up or modify non-compliances, and 52% have skilled audit points and failures associated to non-production knowledge.

However the price of a knowledge breach can go previous the positive, as a portion of the misplaced income comes from halted operations. A current Splunk report discovered that the largest explanation for downtime incidents was cybersecurity-related human errors, akin to clicking a phishing hyperlink.

Unplanned downtime prices the world’s largest corporations $400 billion a yr, with contributors together with direct income loss, diminished shareholder worth, stagnant productiveness, and reputational injury. Certainly, ransomware injury prices are predicted to exceed $265 billion by 2031.

In response to IBM, the common value of a knowledge breach in 2024 is $4.88 million, a ten% enhance over 2023. The tech big’s report added that 40% of breaches concerned knowledge saved throughout a number of environments, like public cloud and on-prem, and these value greater than $5 million on common and took the longest to determine and include. This reveals that enterprise leaders are proper to be involved about knowledge sprawl.

SEE: Almost 10 Billion Passwords Leaked in Greatest Compilation of All Time

Taking steps to safe knowledge in non-production environments may be resource-intensive

There are methods that knowledge saved in non-production environments may be secured, like by masking the delicate knowledge. Nevertheless, the Perforce report discovered that companies have a number of the reason why they’re reluctant to take action, together with that respondents discover it troublesome and time-consuming, and since it could decelerate the organisation.

  • Almost a 3rd are involved that it could decelerate software program improvement, as replicating manufacturing databases to non-production environments securely can take weeks.
  • 36% say masked knowledge may be unrealistic and due to this fact impression software program high quality.
  • 38% assume the safety protocols might inhibit the corporate’s potential to trace and adjust to rules.

The report additionally discovered that 86% of organisations enable knowledge compliance exceptions in non-production environments to keep away from the trouble of storing it securely. These embody utilizing a restricted knowledge set, knowledge minimisation, or gaining consent from the info topic.

Suggestions for securing delicate knowledge in non-production environments

The Perforce group outlined the highest 4 methods companies can safe their delicate knowledge in non-production environments:

  1. Static knowledge masking: Completely changing delicate values with fictitious, but lifelike equivalents.
  2. Knowledge loss prevention (DLP): A fringe-defence safety strategy that detects potential knowledge breaches and theft and makes an attempt to forestall them.
  3. Knowledge encryption: Quickly converts knowledge into code, permitting solely authorised customers to entry the info.
  4. Strict entry management: A coverage that categorises customers by roles and different attributes and configures these customers’ entry to datasets based mostly on these classes.

The authors wrote: “Defending delicate knowledge generally is just not simple to do. AI/ML provides to that complexity.

“Instruments that specialize in defending delicate knowledge in different non-production environments — improvement, testing, and analytics, for instance — are well-positioned that can assist you shield your AI surroundings.”