Во втором выводит 0.Значит всё что выше вызова
.performFetch()
неверно. Где-то тут var fetchedResultsController = CoreDataManager.instance.fetchedResultsController("Customer", keyForSort: "name")
Как надо, смотрите тут https://developer.apple.com/documentation/coredata... потом проверить все что писал выше. Если всё это не поможет, будем думать дальше. if let ... , guard let ...
https://developer.apple.com/documentation/coredata... func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if section == 0 {
let sections = fetchedResultsController.sections
return sections![section].numberOfObjects // <-- Cюда брейкпоинт
}
else if section == 1 {
let sections2 = fetchedResultsController2.sections
return sections2![section].numberOfObjects
}
else {
return 1
}
}
, а в консоли e sections.count
, если тут будет ошибка, тогда надо смотреть выше, а там у нас fetchedResultsController. Выведи в методе override func viewDidLoad()
в конце метода print(fetchedResultsController.fetchedObjects?.count)
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]