Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions iBox/Resources/iBox.xcdatamodeld/iBox.xcdatamodel/contents
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="1" systemVersion="11A491" minimumToolsVersion="Automatic" sourceLanguage="Swift" usedWithCloudKit="false" userDefinedModelVersionIdentifier="">
<elements/>
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="22522" systemVersion="23C71" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
<entity name="BookmarkEntity" representedClassName="BookmarkEntity" syncable="YES" codeGenerationType="class">
<attribute name="id" optional="YES" attributeType="UUID" usesScalarValueType="NO"/>
<attribute name="name" attributeType="String"/>
<attribute name="order" optional="YES" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES"/>
<attribute name="url" attributeType="URI"/>
<relationship name="folder" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="FolderEntity" inverseName="bookmarks" inverseEntity="FolderEntity"/>
</entity>
<entity name="FolderEntity" representedClassName="FolderEntity" syncable="YES" codeGenerationType="class">
<attribute name="color" attributeType="String"/>
<attribute name="id" optional="YES" attributeType="UUID" usesScalarValueType="NO"/>
<attribute name="name" attributeType="String"/>
<attribute name="order" optional="YES" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES"/>
<relationship name="bookmarks" optional="YES" toMany="YES" deletionRule="Nullify" ordered="YES" destinationEntity="BookmarkEntity" inverseName="folder" inverseEntity="BookmarkEntity"/>
</entity>
</model>
45 changes: 0 additions & 45 deletions iBox/Sources/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,50 +32,5 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
}

// MARK: - Core Data stack

lazy var persistentContainer: NSPersistentContainer = {
/*
The persistent container for the application. This implementation
creates and returns a container, having loaded the store for the
application to it. This property is optional since there are legitimate
error conditions that could cause the creation of the store to fail.
*/
let container = NSPersistentContainer(name: "iBox")
container.loadPersistentStores(completionHandler: { (storeDescription, error) in
if let error = error as NSError? {
// 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.

/*
Typical reasons for an error here include:
* The parent directory does not exist, cannot be created, or disallows writing.
* The persistent store is not accessible, due to permissions or data protection when the device is locked.
* The device is out of space.
* The store could not be migrated to the current model version.
Check the error message to determine what the actual problem was.
*/
fatalError("Unresolved error \(error), \(error.userInfo)")
}
})
return container
}()

// MARK: - Core Data Saving support

func saveContext () {
let context = persistentContainer.viewContext
if context.hasChanges {
do {
try context.save()
} catch {
// 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.
let nserror = error as NSError
fatalError("Unresolved error \(nserror), \(nserror.userInfo)")
}
}
}

}

3 changes: 2 additions & 1 deletion iBox/Sources/Model/Bookmark.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import Foundation

struct Bookmark: Codable {
let id: UUID
let name: String
let url: String
let url: URL
}
3 changes: 2 additions & 1 deletion iBox/Sources/Model/Folder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
import Foundation

struct Folder {
var id: UUID
let name: String
let color: ColorName
let bookmarks: [Bookmark]
var isOpened: Bool = true
var isOpened: Bool = false
}

2 changes: 1 addition & 1 deletion iBox/Sources/Presenter/BoxList/BoxListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import UIKit
import SnapKit

protocol BoxListViewDelegate: AnyObject {
func didSelectWeb(at url: String, withName name: String)
func didSelectWeb(at url: URL, withName name: String)
}

class BoxListView: BaseView {
Expand Down
5 changes: 2 additions & 3 deletions iBox/Sources/Presenter/BoxList/BoxListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@ class BoxListViewController: BaseNavigationBarViewController<BoxListView> {
}

extension BoxListViewController: BoxListViewDelegate {
func didSelectWeb(at url: String, withName name: String) {
let viewController = PreloadedWebViewController()
func didSelectWeb(at url: URL, withName name: String) {
let viewController = PreloadedWebViewController(selectedWebsite: url)
viewController.title = name
viewController.selectedWebsite = url
navigationController?.pushViewController(viewController, animated: true)
}
}
4 changes: 2 additions & 2 deletions iBox/Sources/Presenter/Web/PreloadedWebView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import WebKit
import SnapKit

class PreloadedWebView: BaseView {
var selectedWebsite: String? {
var selectedWebsite: URL? {
didSet {
getWebView()
}
Expand All @@ -30,7 +30,7 @@ class PreloadedWebView: BaseView {

private func getWebView() {
guard let selectedWebsite else { return }
webView = WebViewPreloader.shared.getWebView(for: URL(string: selectedWebsite)!)
webView = WebViewPreloader.shared.getWebView(for: selectedWebsite)
guard let webView else { return }
addSubview(webView)
webView.snp.makeConstraints { make in
Expand Down
18 changes: 13 additions & 5 deletions iBox/Sources/Presenter/Web/PreloadedWebViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,17 @@
import UIKit

class PreloadedWebViewController: BaseNavigationBarViewController<PreloadedWebView> {
var selectedWebsite: String?

var selectedWebsite: URL

init(selectedWebsite: URL) {
self.selectedWebsite = selectedWebsite
super.init(nibName: nil, bundle: nil)
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .backgroundColor
Expand All @@ -21,9 +30,8 @@ class PreloadedWebViewController: BaseNavigationBarViewController<PreloadedWebVi

override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)

guard let selectedWebsite else { return }
WebViewPreloader.shared.resetWebView(for: URL(string: selectedWebsite)!)

WebViewPreloader.shared.resetWebView(for: selectedWebsite)
}

override func setupNavigationBar() {
Expand Down
26 changes: 23 additions & 3 deletions iBox/Sources/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
// 앱 테마 정보
window?.overrideUserInterfaceStyle = window?.toUserInterfaceStyle(UserDefaultsManager.theme.value) ?? .unspecified

insertDefaultDataIfNeeded()

// 나중에 userDefaults에 저장해두고 꺼내와서 preload하기
let urlsToPreload = [
URL(string: "https://profile.intra.42.fr/")!,
Expand All @@ -32,9 +34,9 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
WebViewPreloader.shared.preload(urls: urlsToPreload)

let favorite = UserDefaultsManager.favorite.value
guard let favoriteUrl = URL(string: favorite.url) else { return }
let favoriteUrl = favorite.url
WebViewPreloader.shared.preloadFavoriteView(url: favoriteUrl)

window?.rootViewController = MainTabBarController()
window?.makeKeyAndVisible() // 윈도우를 화면에 보여줌

Expand All @@ -48,6 +50,25 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
}
}

private func insertDefaultDataIfNeeded() {
let isDefaultDataInserted = UserDefaultsManager.isDefaultDataInserted.value
if !isDefaultDataInserted {
var defaultData = [
Folder(id: UUID(), name: "42 폴더", color: .gray, bookmarks: [
Bookmark(id: UUID(), name: "42 Intra", url: URL(string: "https://profile.intra.42.fr/")!),
Bookmark(id: UUID(), name: "42Where", url: URL(string: "https://www.where42.kr/")! ),
Bookmark(id: UUID(), name: "42Stat", url: URL(string: "https://stat.42seoul.kr/")!),
Bookmark(id: UUID(), name: "집현전", url: URL(string: "https://42library.kr/")!),
Bookmark(id: UUID(), name: "Cabi", url: URL(string: "https://cabi.42seoul.io/")!),
Bookmark(id: UUID(), name: "24HANE", url: URL(string: "https://24hoursarenotenough.42seoul.kr/")!)
])
]
CoreDataManager.shared.deleteAllFolders()
CoreDataManager.shared.addInitialFolders(defaultData)
UserDefaultsManager.isDefaultDataInserted.value = true
}
}

func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
if let urlContext = URLContexts.first {
let url = urlContext.url
Expand Down Expand Up @@ -87,7 +108,6 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
// to restore the scene back to its current state.

// Save changes in the application's managed object context when the application transitions to the background.
(UIApplication.shared.delegate as? AppDelegate)?.saveContext()
}


Expand Down
Loading