BLOGSWIFT Telegram 9
Better self-executing closures

Очень часто мы используем self-executing closure для настройки объектов в Swift. В основном именно во view слое, реже – в других частях код-базы. И хотя такие closure невероятно удобны, их можно улучшить: уменьшить размер, не ухудшив читаемость кода.

Сегодня хотел бы рассказать вам о функции-утилите, которую я повсеместно использую в своих проектах. Функция configure принимает любой объект или значение, используя ключевое слово inout, модифицирует его по ссылке и возвращает.

Звучит достаточно просто? Так и есть. Я добавил еще атрибут discardableResult, чтобы в случае необходимости игнорировать возвращаемое значение, и rethrows, чтобы не использовать try/catch для closure, которые не выбрасывают ошибки.

Функцию можно объявить глобально в проекте или использовать мой SDK: PimineUtilities, где эта функция уже реализована.

Source / PimineSDK
#utilities #closures #intermediate



tgoop.com/BlogSwift/9
Create:
Last Update:

Better self-executing closures

Очень часто мы используем self-executing closure для настройки объектов в Swift. В основном именно во view слое, реже – в других частях код-базы. И хотя такие closure невероятно удобны, их можно улучшить: уменьшить размер, не ухудшив читаемость кода.

Сегодня хотел бы рассказать вам о функции-утилите, которую я повсеместно использую в своих проектах. Функция configure принимает любой объект или значение, используя ключевое слово inout, модифицирует его по ссылке и возвращает.

Звучит достаточно просто? Так и есть. Я добавил еще атрибут discardableResult, чтобы в случае необходимости игнорировать возвращаемое значение, и rethrows, чтобы не использовать try/catch для closure, которые не выбрасывают ошибки.

Функцию можно объявить глобально в проекте или использовать мой SDK: PimineUtilities, где эта функция уже реализована.

Source / PimineSDK
#utilities #closures #intermediate

BY SWIFTER | Блог про Swift




Share with your friend now:
tgoop.com/BlogSwift/9

View MORE
Open in Telegram


Telegram News

Date: |

With the sharp downturn in the crypto market, yelling has become a coping mechanism for many crypto traders. This screaming therapy became popular after the surge of Goblintown Ethereum NFTs at the end of May or early June. Here, holders made incoherent groaning sounds in late-night Twitter spaces. They also role-played as urine-loving Goblin creatures. Other crimes that the SUCK Channel incited under Ng’s watch included using corrosive chemicals to make explosives and causing grievous bodily harm with intent. The court also found Ng responsible for calling on people to assist protesters who clashed violently with police at several universities in November 2019. Your posting frequency depends on the topic of your channel. If you have a news channel, it’s OK to publish new content every day (or even every hour). For other industries, stick with 2-3 large posts a week. But a Telegram statement also said: "Any requests related to political censorship or limiting human rights such as the rights to free speech or assembly are not and will not be considered." The initiatives announced by Perekopsky include monitoring the content in groups. According to the executive, posts identified as lacking context or as containing false information will be flagged as a potential source of disinformation. The content is then forwarded to Telegram's fact-checking channels for analysis and subsequent publication of verified information.
from us


Telegram SWIFTER | Блог про Swift
FROM American