-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
통계뷰에 CoreData 붙이기(진행중) #35
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
ThrowAway/ThrowAway/SwiftUI/StaticsView/StatisticsView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// | ||
// StatisticsView.swift | ||
// ThrowAway | ||
// | ||
// Created by 지준용 on 2022/10/30. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct StatisticsView: View { | ||
|
||
@EnvironmentObject var dateHolder: DateHolder | ||
@Environment(\.managedObjectContext) private var viewContext | ||
|
||
@FetchRequest( | ||
sortDescriptors: [NSSortDescriptor(keyPath: \Product.cleaningDay, ascending: true)], | ||
animation: .default | ||
) | ||
private var products: FetchedResults<Product> | ||
|
||
private let setWidth = UIScreen.main.bounds.width | ||
private let screenWidth = UIScreen.main.bounds.width | ||
|
||
var body: some View { | ||
VStack { | ||
VStack { | ||
DateScrollView() | ||
.environmentObject(dateHolder) | ||
|
||
Text("이번 달의 달성도는 81%입니다.") | ||
.padding(.vertical, 20) | ||
.font(.system(size: 20)) | ||
|
||
DayOfWeekView() | ||
CalendarView() | ||
} | ||
.padding(.horizontal, 16) | ||
|
||
// TODO: 조건에 맞는 물건을 coredata에서 불러오기 | ||
let notYetCleaningProducts = products.filter{ $0.isCleanedUp == false } | ||
let lateCleanedUpProducts = products.filter{ $0.isCleanedUp == false } | ||
|
||
makeSectionView(label: "버리지 못한 물건", products: notYetCleaningProducts) | ||
makeSectionView(label: "늦게 버린 물건", products: lateCleanedUpProducts) | ||
} | ||
} | ||
|
||
private func makeSectionView(label: String, products: [Product]) -> some View { | ||
VStack(alignment: .leading) { | ||
HStack { | ||
Text("\(label)(\(products.count))") | ||
.font(.system(size: 18)) | ||
.fontWeight(.semibold) | ||
.padding(.top, 10) | ||
Spacer() | ||
} | ||
makeHorizontalScrollView(from: products) | ||
} | ||
.padding(.leading, 16) | ||
} | ||
|
||
private func makeHorizontalScrollView(from products: [Product]) -> some View { | ||
let items: [(id: ObjectIdentifier, image: Image)] = products.map { product in | ||
var image = Image(systemName: "photo") | ||
if (product.photo != nil), let photo = Image(data: product.photo!) { | ||
image = photo | ||
} | ||
return (product.id, image: image) | ||
} | ||
|
||
return ScrollView(.horizontal) { | ||
HStack { | ||
ForEach(items, id: \.self.id) { item in | ||
item.image | ||
.resizable() | ||
.frame(width: screenWidth / 6, height: screenWidth / 6, alignment: .center) | ||
.aspectRatio(contentMode: .fit) | ||
.clipShape(Circle()) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
Comment on lines
+62
to
+83
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 사용자가 사진을 등록하지 않아 coredata 에 없다면, 기본 이미지를 적용하도록 했습니다. |
||
|
||
private extension Image { | ||
init?(data: Data) { | ||
guard let image = UIImage(data: data) else { return nil } | ||
self = .init(uiImage: image) | ||
} | ||
} |
66 changes: 0 additions & 66 deletions
66
ThrowAway/ThrowAway/SwiftUI/StaticsView/View/StatisticsView.swift
This file was deleted.
Oops, something went wrong.
3 changes: 2 additions & 1 deletion
3
ThrowAway/ThrowAway/ThrowAway.xcdatamodeld/ThrowAway.xcdatamodel/contents
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="20086" systemVersion="21C52" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier=""> | ||
<entity name="Product" representedClassName="Product" syncable="YES"> | ||
<attribute name="cleanedUpDay" optional="YES" attributeType="Date" usesScalarValueType="NO"/> | ||
<attribute name="cleaningDay" optional="YES" attributeType="Date" usesScalarValueType="NO"/> | ||
<attribute name="isCleanedUp" optional="YES" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/> | ||
<attribute name="memo" optional="YES" attributeType="String"/> | ||
<attribute name="photo" optional="YES" attributeType="Binary"/> | ||
<attribute name="title" optional="YES" attributeType="String"/> | ||
</entity> | ||
<elements> | ||
<element name="Product" positionX="-63" positionY="-18" width="128" height="104"/> | ||
<element name="Product" positionX="-63" positionY="-18" width="128" height="119"/> | ||
</elements> | ||
</model> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FetchResults 는 여기서 값을 수정할 수 없더군요 ㅜㅜ 수정이 필요합니다