NavigationStack(path: $presentedParks) { List(parks) { park in NavigationLink(park.name, value: park) } .navigationDestination(for: Park.self) { park in ParkDetails(park: park) } }
NavigationStack(path: $presentedPaths) { List { ForEach(parks) { park in NavigationLink(park.name, value: park) } ForEach(zoos) { zoo in NavigationLink(zoo.name, value: zoo) } } .navigationDestination(for: Park.self) { park in ParkDetails(park: park) } .navigationDestination(for: Zoo.self) { zoo in ZooDetails(park: zoo) } }
NavigationPath也支持简单的数据添加和删除元素的等操作。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/// Appends a new value to the end of this path. publicmutatingfuncappend<V>(_value: V) whereV : Hashable
/// Appends a new codable value to the end of this path. publicmutatingfuncappend<V>(_value: V) whereV : Decodable, V : Encodable, V : Hashable
/// Removes values from the end of this path. /// /// - Parameters: /// - k: The number of values to remove. The default value is `1`. /// /// - Precondition: The input parameter `k` must be greater than or equal /// to zero, and must be less than or equal to the number of elements in /// the path. publicmutatingfuncremoveLast(_k: Int=1)
enumAppViewRouter: Hashable { enumCategory: Hashable { case list case detail(Int) } case profile case category(Category) var title: String { switchself { case .profile: return"Profile" case .category(let category): switch category { case .list: return"Category List" case .detail(let id): return"Category Detail: \(id)" } } } }
init(inMemory: Bool=false) { container =NSPersistentCloudKitContainer(name: "CoreDataDemo") if inMemory { container.persistentStoreDescriptions.first!.url =URL(fileURLWithPath: "/dev/null") } container.loadPersistentStores(completionHandler: { (storeDescription, error) in iflet error = error asNSError? { // Replace this implementation with code to handle the error appropriately. // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. fatalError("Unresolved error \(error), \(error.userInfo)") } }) container.viewContext.automaticallyMergesChangesFromParent =true } }
finalclassMyPersistenceController { structConfiguration { let containerClass: NSPersistentCloudKitContainer.Type let name: String let managedObjectModel: NSManagedObjectModel? init(containerClass: NSPersistentCloudKitContainer.Type, name: String, managedObjectModel: NSManagedObjectModel? =nil) { self.containerClass = containerClass self.name = name self.managedObjectModel = managedObjectModel } } let container: NSPersistentCloudKitContainer init(_configuration: MyPersistenceController.Configuration) { iflet managedObjectModel = configuration.managedObjectModel { container = configuration.containerClass.init(name: configuration.name, managedObjectModel: managedObjectModel) } else { container = configuration.containerClass.init(name: configuration.name) } container.loadPersistentStores(completionHandler: { (storeDescription, error) in iflet error = error asNSError? { // Replace this implementation with code to handle the error appropriately. // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. #ifDEBUG fatalError("Unresolved error \(error), \(error.userInfo)") #else #endif } }) } }
在CocoaPods的使用过程中,会根据Podfile的内容,来抓取第三方库的源文件和生成其它相关的文件。这些文件均存放在Pods目录中,并通过生成的Pods.xcodeproj项目来进行管理。除此之外,还有几个关键的文件位于目录:Pods/Target Support Files/Pods-XXX/ 中,下面会讲到如何使用它们来解决我们标题中的问题。