Да, go впереди!
Да, я думаю, вы должны создать Package
структуру и затем сгенерировать array of Package(s)
.
Вот код.
1. Определите структуру пакета 100
struct Package {
let name: String
let package: String
let description: String
}
2. Загрузите файл 101
guard
let url = Bundle.main.url(forResource: "Packages", withExtension: "txt"),
let content = try? String(contentsOf: url)
else { fatalError() }
3. Извлеките строки 101
let lines = content
.components(separatedBy: CharacterSet.newlines)
.filter { !$0.isEmpty }
.compactMap { $0.components(separatedBy: ": ").last }
4. Извлеките 3 массива ?
let nameLines = lines.enumerated().filter { $0.offset % 3 == 0 }.map { $0.element }
let packageLines = lines.enumerated().filter { $0.offset % 3 == 1 }.map { $0.element }
let descriptionLines = lines.enumerated().filter { $0.offset % 3 == 2 }.map { $0.element }
5. Создайте массив пакетов (ы) ???
let packages = zip(nameLines, zip(packageLines, descriptionLines))
.map { (name: $0, package: $1.0, description: $1.1) }
.map (Package.init)
6. Тест ?
print(packages)
[
Package(name: "LittleX",
package: "com.ioscreatix.littlex",
description: "iPhone X features for Non-X devices on iOS 11, and iPad Dock and PiP for All iOS 11 Devices on iOS 11"
),
Package(name: "InteliX",
package: "com.ioscreatix.intelix",
description: "Grouped Notifications for iOS 11"
)
]