Urgent.News

What's breaking now, across thousands of outlets.

Culture

Как я сделал фильтр планировок Clash of Clans по уровню ратуши в SwiftUI

Я делаю небольшое бесплатное iOS-приложение с планировками баз для Clash of Clans, и одна из первых задач была простой на вид: показать игроку только те базы, которые подходят его ратуше. Что пошло не так в первой версии Сначала я хранил уровень ратуши строкой ("TH16", "TH17"). Сортировка ломалась: "TH9" оказывался после "TH17". Перешёл на Int и отдельный вычисляемый заголовок для интерфейса.…

Original Russian Read in English

The author created a free iOS application featuring Clash of Clans village layouts, aiming to display only the villages that match the player's tower level. The first version of the app stored the tower level as a string (TH16, TH17). Sorting issues arose, as TH9 would appear after TH17. The author switched to using Int and a separate calculated title property for the interface.

The layout struct, Identifiable, included the town hall level, kind (war, farm, trophy), and a dynamic title property. Filtering was done using a computed property, with the selected tower level stored in @State. The filtered list only updates when the filter changes.

Players appreciated the app not only for the villages themselves but also for the filter remembering the player's last tower level. This detail was saved using @AppStorage, allowing users to see their villages upon the next launch. The application, named Base Layouts: War & Farm Maps, is available on the App Store (https://apps.apple.com/app/apple-store/id6804564319?pt=2720803&ct=devto_ru&mt=8). The author welcomes feedback on organizing filters in SwiftUI lists.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Culture

More from Thursday 29 October →