Skip to content

Commit ca9b3c5

Browse files
committed
Refactoring. Add global constant properties
1 parent 65c9017 commit ca9b3c5

File tree

5 files changed

+29
-15
lines changed

5 files changed

+29
-15
lines changed

Clone App/Instagram/Instagram.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
15ACA73D290D80040011E665 /* AuthenticationViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15ACA73B290D80030011E665 /* AuthenticationViewModel.swift */; };
3636
15ACA73E290D80040011E665 /* UserInfoModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15ACA73C290D80040011E665 /* UserInfoModel.swift */; };
3737
15C1848A290FF465004EF35F /* UserService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15C18489290FF465004EF35F /* UserService.swift */; };
38+
15C1848C290FF76E004EF35F /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15C1848B290FF76E004EF35F /* Constants.swift */; };
3839
81BBDDEDACB63985F43988AC /* Pods_Instagram.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5B288DF44C633C67CA7F5E28 /* Pods_Instagram.framework */; };
3940
/* End PBXBuildFile section */
4041

@@ -69,6 +70,7 @@
6970
15ACA73B290D80030011E665 /* AuthenticationViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AuthenticationViewModel.swift; sourceTree = "<group>"; };
7071
15ACA73C290D80040011E665 /* UserInfoModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UserInfoModel.swift; sourceTree = "<group>"; };
7172
15C18489290FF465004EF35F /* UserService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserService.swift; sourceTree = "<group>"; };
73+
15C1848B290FF76E004EF35F /* Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; };
7274
5B288DF44C633C67CA7F5E28 /* Pods_Instagram.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Instagram.framework; sourceTree = BUILT_PRODUCTS_DIR; };
7375
A04279BD0172B03AD23CDDBC /* Pods-Instagram.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Instagram.release.xcconfig"; path = "Target Support Files/Pods-Instagram/Pods-Instagram.release.xcconfig"; sourceTree = "<group>"; };
7476
BDAA046A9094EA0B1DC591AA /* Pods-Instagram.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Instagram.debug.xcconfig"; path = "Target Support Files/Pods-Instagram/Pods-Instagram.debug.xcconfig"; sourceTree = "<group>"; };
@@ -200,6 +202,7 @@
200202
isa = PBXGroup;
201203
children = (
202204
15ACA734290D79FA0011E665 /* Extensions.swift */,
205+
15C1848B290FF76E004EF35F /* Constants.swift */,
203206
);
204207
path = Utils;
205208
sourceTree = "<group>";
@@ -345,6 +348,7 @@
345348
isa = PBXSourcesBuildPhase;
346349
buildActionMask = 2147483647;
347350
files = (
351+
15C1848C290FF76E004EF35F /* Constants.swift in Sources */,
348352
15ACA71B290D79250011E665 /* LoginController.swift in Sources */,
349353
15ACA711290D77960011E665 /* ProfileController.swift in Sources */,
350354
156E22ED290D6EBD0026B0C3 /* ViewController.swift in Sources */,

Clone App/Instagram/Instagram/API/AuthService.swift

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,23 @@
88
import Firebase
99
import FirebaseFirestore
1010

11-
let firestoreUsers = "users"
12-
1311
struct AuthService {
1412

1513
static func handleIsLoginAccount(email: String, pw: String, completion: @escaping (AuthDataResult?,Error?)-> Void) {
16-
Auth.auth().signIn(withEmail: email, password: pw, completion: completion)
14+
AUTH.signIn(withEmail: email, password: pw, completion: completion)
1715
}
1816

1917
static func registerUser(withUserInfo info: RegistrationViewModel, completion: @escaping (Error?)->Void) {
2018
guard let image = info.profileImage else { return }
2119

2220
ImageUploader.uploadImage(image: image) { imageUrl in
23-
Auth.auth().createUser(withEmail: info.email.value, password: info.password.value) { result, error in
21+
AUTH.createUser(withEmail: info.email.value, password: info.password.value) { result, error in
2422
guard error == nil else { print("Fail uploadImage"); return }
2523
guard let uid = result?.user.uid else { return }
2624

2725
let userModel = info.getUserInfoModel(uid: uid, url: imageUrl)
2826
let encodedUserModel = encodeToNSDictionary(codableType: userModel)
29-
Firestore.firestore().collection(firestoreUsers).document(uid).setData(encodedUserModel, completion: completion)
27+
COLLECTION_USERS.document(uid).setData(encodedUserModel, completion: completion)
3028
}
3129
}
3230
}

Clone App/Instagram/Instagram/API/UserService.swift

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,13 @@ struct UserService {
1313

1414
static func updateCurrentUserInfo(CodableType info: UserInfoModel) {
1515
let encodedUserModel = encodeToNSDictionary(codableType: info)
16-
Firestore.firestore().collection(firestoreUsers).document(info.uid).updateData(encodedUserModel)
16+
COLLECTION_USERS.document(info.uid).updateData(encodedUserModel)
1717

1818
}
1919

2020
static func fetchCurrentUserInfo(completion: @escaping (UserInfoModel?)->Void) {
21-
guard let userUID = Auth.auth().currentUser?.uid else { completion((nil)); return }
22-
let db = Firestore.firestore()
23-
let userCollection = db.collection(firestoreUsers)
24-
userCollection.document(userUID).getDocument() { documentSnapshot, error in
21+
guard let userUID = CURRENT_USER?.uid else { completion((nil)); return }
22+
COLLECTION_USERS.document(userUID).getDocument() { documentSnapshot, error in
2523
guard error == nil else { return }
2624
guard let document = documentSnapshot else { return }
2725
do {
@@ -34,9 +32,9 @@ struct UserService {
3432
}
3533

3634
static func fetchUserProfile(userProfile url: String, completion: @escaping (UIImage?) -> Void) {
37-
let storageReference = Storage.storage().reference(forURL: url)
35+
let storageReference = STORAGE.reference(forURL: url)
3836

39-
storageReference.getData(maxSize: userProfileMegaByte) { data, error in
37+
storageReference.getData(maxSize: USERPROFILEIMAGEMEGABYTE) { data, error in
4038
guard error == nil else { return }
4139
guard let data = data else { completion(nil); return }
4240
completion(UIImage(data: data))
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// Constants.swift
3+
// Instagram
4+
//
5+
// Created by 양승현 on 2022/10/31.
6+
//
7+
8+
import Firebase
9+
10+
//MARK: - Constant properties
11+
let USERPROFILEIMAGEMEGABYTE = Int64(1*400*400)
12+
let FIRESTORE_USERS = "users"
13+
let COLLECTION_USERS = Firestore.firestore().collection(FIRESTORE_USERS)
14+
let FIRESTORE_DB = Firestore.firestore()
15+
let CURRENT_USER = Auth.auth().currentUser
16+
let STORAGE = Storage.storage()
17+
let AUTH = Auth.auth()

Clone App/Instagram/Instagram/Utils/Extensions.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
//
77
import UIKit
88

9-
//MARK: - Constant properties
10-
let userProfileMegaByte = Int64(1*400*400)
11-
129
extension UIViewController {
1310
func setupViewGradientBackground() {
1411
let gradient = CAGradientLayer()

0 commit comments

Comments
 (0)