class Customer { }
class Seller { }
var customer = Customer()
var seller = Seller()
var data: Any = customer
switch data {
case is Customer:
print("Customer") // Customer
case is Seller:
print("Customer")
default:
break
}
switch type(of: data) {
case Customer.self:
case Seller.self:
//...
}
UIViewController
этой сущности я Вас правильно понял? func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state.
// This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message)
// or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks.
// Games should use this method to pause the game.
}
func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application
// state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate:
// when the user quits.
}
func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the active state; here you can undo many of the
// changes made on entering the background.
}
func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the
// application was previously in the background, optionally refresh the user interface.
}
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate.
// See also applicationDidEnterBackground:.
}
import Foundation
var linesOfData = [Data]()
let tmp: Data = Data([1, 2, 3, 5, 3, 2, 1, 5])
let index1 = tmp.index(of: 5)
linesOfData.append(tmp.prefix(upTo: index1!))
let index2 = tmp.suffix(from: index1! + 1).index(of: 5)
linesOfData.append(tmp.suffix(from: index1! + 1).prefix(upTo: index2!))
print(linesOfData) // [3 bytes, 3 bytes]
var linesOfData = [Data]()
let tmp: Data = getNewData()
let index1 = tmp.index(of: ...)
linesOfData.append(tmp.prefix(upTo: index1)) /// 1
let index2 = tmp.suffix(from: index).index(of: ...)
linesOfData.append(tmp.suffix(from: index).prefix(upTo: index2)) /// 2
и так далее
можно всё это красиво обернуть в функцию
тут такой гемор только из-за того факта что вы хотите O(1)
ЭТО ЛИШЬ ПРИМЕР и эту идею можно красиво обернуть в функцию которая так пробежится по всей строке которую выплюнула функцию getNewData()