Files
InvestmentTrackerApp/PortfolioJournal/Views/Settings/AllocationTargetsView.swift
T
alexandrev-tibco a8a9ad64f3 Xcode 27: compila sin warnings y migra API deprecadas de SwiftUI
- Imports de CoreData que faltaban (MemberImportVisibility) en AccountsView,
  ImportDataView, ChartsContainerView y AddSourceView.
- Aislamiento MainActor: IsolatedDefaultValues en el target de la app,
  LinearGradient @MainActor, WatchSyncMessage nonisolated, closures de
  ReviewPromptService/MonthlyCheckInStore/AppIntents.
- Warnings de valores sin usar (SnapshotGapDetector, DashboardLayoutStore,
  OnboardingView, GoalEditorView, CoreDataStack, SettingsViewModel).
- foregroundColor→foregroundStyle, cornerRadius→clipShape,
  navigationBarLeading/Trailing→topBarLeading/Trailing,
  Task.sleep(nanoseconds:)→sleep(for:), NavigationLink(isActive:)→
  navigationDestination(isPresented:).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01F1u4K16xy7eQVtgsYNZ9Vn
2026-09-16 11:44:49 +02:00

91 lines
3.0 KiB
Swift

import SwiftUI
struct AllocationTargetsView: View {
@StateObject private var categoryRepository = CategoryRepository()
@State private var targetValues: [UUID: String] = [:]
var body: some View {
List {
Section {
HStack {
Text("Total Targets")
Spacer()
Text(String(format: "%.0f%%", totalTargets))
.foregroundStyle(totalTargets == 100 ? Color.positiveGreen : .secondary)
}
if totalTargets != 100 {
Text("Targets don't need to be perfect, but aiming for 100% keeps the drift view accurate.")
.font(.caption)
.foregroundStyle(.secondary)
}
}
Section {
ForEach(categoryRepository.categories) { category in
let categoryId = category.id
HStack {
HStack(spacing: 8) {
Circle()
.fill(category.color)
.frame(width: 10, height: 10)
Text(category.name)
}
Spacer()
TextField("0", text: targetBinding(for: categoryId))
.keyboardType(.decimalPad)
.multilineTextAlignment(.trailing)
.frame(width: 60)
Text("%")
.foregroundStyle(.secondary)
}
}
} header: {
Text("Targets by Category")
} footer: {
Text("Set your desired allocation percentages to track drift over time.")
}
}
.navigationTitle("Allocation Targets")
.navigationBarTitleDisplayMode(.inline)
.onAppear {
preloadTargets()
}
}
private var totalTargets: Double {
let ids = categoryRepository.categories.compactMap { $0.id }
return AllocationTargetStore.totalTargetPercentage(for: ids)
}
private func preloadTargets() {
targetValues = categoryRepository.categories.reduce(into: [:]) { result, category in
let id = category.id
if let target = AllocationTargetStore.target(for: id) {
result[id] = String(format: "%.0f", target)
}
}
}
private func targetBinding(for categoryId: UUID) -> Binding<String> {
Binding(
get: { targetValues[categoryId] ?? "" },
set: { newValue in
targetValues[categoryId] = newValue
let sanitized = newValue.replacingOccurrences(of: ",", with: ".")
let value = Double(sanitized) ?? 0
AllocationTargetStore.setTarget(value, for: categoryId)
}
)
}
}
#Preview {
NavigationStack {
AllocationTargetsView()
}
}