и посмотреть медиа
Swift | Interview Questions
и посмотреть медиа
Swift interview questions, tests and tasks for iOS developers in Telegram.
Swift interview questions, tests and tasks for iOS developers in Telegram.
AI bot for text-to-speech and voice cloning in Telegram. Create audio using neural network quickly and easily.
The channel is dedicated to preparing for Swift language interviews. It contains current questions, tests, practical tasks and vacancy information. Ideal for beginner and experienced iOS developers who want to refresh their knowledge and successfully pass interviews.
🤔 Какие паттерны знаешь? Паттерны проектирования – это готовые решения частых задач, улучшающие структуру кода, его поддержку и масштабируемость. 🚩Порождающие паттерны (Creational) Помогают упростить создание объектов и сделать его гибким. Определяет интерфейс для создания объекта, но поручает подклассам выбрать его тип. protocol Button { func press() } class iOSButton: Button { func press() { print("iOS button pressed") } } class AndroidButton: Button { func press() { print("Android button pressed") } } class ButtonFactory { static func createButton(for os: String) -> Button { return os == "iOS" ? iOSButton() : AndroidButton() } } let button = ButtonFactory.createButton(for: "iOS") button.press() // "iOS button pressed" 🟠Одиночка (Singleton) Гарантирует, что у класса будет только один экземпляр. class Database { static let shared = Database() // Единственный экземпляр private init() { } func query() { print("Запрос в базу данных") } } Database.shared.query() 🟠Строитель (Builder) Позволяет пошагово создавать сложные объекты. class Burger { var cheese = false var bacon = false } class BurgerBuilder { private var burger = Burger() func addCheese() -> Self { burger.cheese = true return self } func addBacon() -> Self { burger.bacon = true return self } func build() -> Burger { return burger } } let myBurger = BurgerBuilder().addCheese().addBacon().build() print(myBurger.cheese) // true print(myBurger.bacon) // true 🚩Структурные паттерны (Structural) Определяют удобные способы связи между объектами. 🟠Адаптер (Adapter) Позволяет совместить несовместимые интерфейсы. protocol EuropeanSocket { func provide220V() } class EuropeanPlug: EuropeanSocket { func provide220V() { print("220V подано") } } class USPlug { func provide110V() { print("110V подано") } } // Адаптер для американской вилки class USAdapter: EuropeanSocket { private let usPlug: USPlug init(usPlug: USPlug) { self.usPlug = usPlug } func provide220V() { usPlug.provide110V() print("Адаптация до 220V") } } let adapter = USAdapter(usPlug: USPlug()) adapter.provide220V() // "110V подано" // "Адаптация до 220V" 🟠Декоратор (Decorator) Динамически добавляет объекту новое поведение. protocol Coffee { func cost() -> Int } class SimpleCoffee: Coffee { func cost() -> Int { return 100 } } // Декоратор "Молоко" class MilkDecorator: Coffee { private let coffee: Coffee init(_ coffee: Coffee) { self.coffee = coffee } func cost() -> Int { return coffee.cost() + 30 } } let coffee = MilkDecorator(SimpleCoffee()) print(coffee.cost()) // 130 Ставь 👍 и забирай 📚 Базу знаний
Открыть канал и посмотреть медиаOnly registered users can share their opinion.
Be the first to share your impression of this resource!