-
Notifications
You must be signed in to change notification settings - Fork 4
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
Edit Calculator && Use NaverOpenAPI #11
base: hyeongseok
Are you sure you want to change the base?
Conversation
- Delete duplicate - Change logic, some naming
swap을 calculatorView에서 동작하도록 해서 ScreenView 권한 최소화
if configuration.isPressed { | ||
Color(white: 1.0, opacity: 0.3) | ||
} | ||
configuration.label |
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.
상수는 따로 모아서 처리해주면 좋겠네요
} | ||
return numberFormatter.string(from: NSNumber(value: doubleValue)) ?? self | ||
let decimalFractionComponents = components(separatedBy: ".") | ||
guard let decimalString = decimalFractionComponents.first, |
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.
코드를 그대로 사용한 것이지만, 문법은 통일해 주세요.
guard let safeValue = unsafeValue else {
return
}
vs
guard let safeValue = unsafeValue
else { return }
} | ||
return calculationResult / newValue | ||
case .multiply: | ||
return calculationResult * newValue | ||
} | ||
} | ||
} | ||
|
||
extension Calculator { | ||
enum Button: Hashable { |
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.
Button ?
// MARK: - Constant(s) | ||
|
||
extension ScreenView { | ||
private enum DrawConstants { |
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.
👍🏻
import SwiftUI | ||
|
||
class CalculatorManager: ObservableObject { | ||
|
||
// MARK: Alia(es) |
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.
오타
|
||
typealias BinaryOperator = CalculatorManager.BinaryOperator | ||
typealias Digit = CalculatorManager.Digit | ||
|
||
// MARK: Propery(ies) | ||
|
||
private(set) var displayValue = "0" | ||
private(set) var isAllClear = true | ||
private var calculationResult: Decimal? = 0 | ||
private var newValue: Decimal? = nil |
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.
네이밍 개선하면 가독성을 더 올릴 수 있을 거 같네요.
struct BoxOffice: Searchable { | ||
var searchKeyword = "" | ||
var elements: [Any] = [] | ||
var path = "/v1/search/movie.json" |
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.
var ?
|
||
struct BoxOffice: Searchable { | ||
var searchKeyword = "" | ||
var elements: [Any] = [] |
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.
뭐하는 변수인가요 ? Any ?
|
||
import Foundation | ||
|
||
protocol Searchable { |
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.
초기화 함수와 아래 세 값들이 있다면 검색할 수 있는 건가요 ?
static let host = "openapi.naver.com" | ||
} | ||
|
||
class Finder<Article: Searchable>: ObservableObject { |
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.
아직 모듈이 미완성인 것 같네요.
네트워크를 요청할 때 필수로 있어야 하는 것들을 모아서 처리할 수 있도록 해봅시다.
선택적으로 구성해야할 것은 구현할 수 있도록 빼보세요.
네임스페이스 안에 적절한 멤버들이 있도록 해보세요.
if isEqual { | ||
isPreOperatorEqual = true | ||
} | ||
calculationResult = calculate(`operator`, newValue) | ||
guard let calculationResult = calculationResult else { | ||
displayValue = "오류" |
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.
"오류"라는 string 값이 많은데,
이거 상수로 두고 모든 부분에 적용시키면 나중에 하나만 변경시켜도 되니까 좀더 관리하기 쉬울것같아요 ㅎㅎ
let errorMessage = "오류"
displayValue = errorMessage 이렇게?
init?(htmlString: String) { | ||
let option: [NSAttributedString.DocumentReadingOptionKey: NSAttributedString.DocumentType] = [.documentType: .html] | ||
guard let htmlData = htmlString.data(using: .utf16), | ||
let nsStr = try? NSAttributedString(data: htmlData, options: option, documentAttributes: nil) |
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.
줄임말은 지양합시당
var elements: [Any] = [] | ||
var path = "/v1/search/movie.json" | ||
|
||
init() {} |
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.
무엇을 위해 존재하는 init() 일까요
|
||
struct Movie: Codable, Identifiable { | ||
let attributedTitle: AttributedString? | ||
let image: String |
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.
image가 string값이 혹시 맞을까요?
만약 image 의 url을 의미하는 거면 imageURL이 더 좋을 것 같아요~
} | ||
|
||
class Finder<Article: Searchable>: ObservableObject { | ||
@Published var model = Article() |
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.
model 네이밍이 추상적이에요
guard let url = urlComponents.url | ||
else { return } | ||
var urlRequest = URLRequest(url: url) | ||
urlRequest.httpMethod = "GET" |
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.
httpmethod도 종류별로 관리할 수 있으면 좋을것같아요
string을 직접 집어넣는것은 조금 지양해보도록 해봐요!
else { return } | ||
DispatchQueue.main.async { [weak self] in | ||
self?.model.elements = parsedData.items.indices.map { | ||
BoxOffice.Movie(parsedData.items[$0], id: parsedData.start + $0) |
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.
좀더 좋은 방법은 없을까요??
} | ||
} | ||
task.resume() | ||
fetchingStatus = .idle |
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.
resume()하고 .idle 상태로 보내는 것이 확실히 맞을까요?
|
||
struct News: Codable { | ||
let title: String | ||
let originallink: String |
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.
카멜케이스
} | ||
} | ||
|
||
struct Response: Codable { |
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.
네이밍이 모호해용
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.
알고있을지 모르겠지만 codable하는 모델들의 row한 네이밍들을 codingkey을 이용해 자신이 원하는 네이밍으로 변경할 수 있어요
모른다면 꽤 유용하니 한번 찾아봐요 :D
Finder의 fetch 메서드를 모든 타입(news, movie, document)에서 사용 할 수 있도록 만들고 싶지만 아직 구현하지 못함.
// matchedGeometryEffect error Refactor
Calculator
Network
------------>
Network와 viewModel에서 제네릭스를 사용해서 중복되는 코드들을 하나의 함수로 만들어 사용하고 파라미터만 다르게 해서 사용할 수 있도록 하기 위해 매우매우 많은 시간을 고민했지만 해결하지 못했습니다
Network와 Combine은 물론 제네릭스같은 Swift 기능들도 많이 미숙해 공부가 더 많이 필요할 것 같습니다..