Skip to content
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

Feature/file #47

Merged
merged 3 commits into from
May 5, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions OneDayOneAnswer/OneDayOneAnswer.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
08331E8B245C2154001103A6 /* 42-JMJ-Question.tsv in Resources */ = {isa = PBXBuildFile; fileRef = 08331E8A245C2154001103A6 /* 42-JMJ-Question.tsv */; };
08493A92245708B3002876D3 /* DataBase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08493A91245708B3002876D3 /* DataBase.swift */; };
08493A9424570923002876D3 /* TestDataBase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08493A9324570923002876D3 /* TestDataBase.swift */; };
088F336B24601B58003B851D /* FileUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 088F336A24601B58003B851D /* FileUtils.swift */; };
088F336E2460349D003B851D /* test_image.png in Resources */ = {isa = PBXBuildFile; fileRef = 088F336D2460349D003B851D /* test_image.png */; };
08F6191324586B21006E0233 /* SqliteDataBase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08F6191224586B21006E0233 /* SqliteDataBase.swift */; };
52963ABC2456C5020021AAE6 /* MapoFlowerIsland.otf in Resources */ = {isa = PBXBuildFile; fileRef = 52963ABB2456C5020021AAE6 /* MapoFlowerIsland.otf */; };
52963AC02456D4D70021AAE6 /* GyeonggiBatang.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 52963ABF2456D4D70021AAE6 /* GyeonggiBatang.ttf */; };
Expand All @@ -31,6 +33,8 @@
08331E8A245C2154001103A6 /* 42-JMJ-Question.tsv */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "42-JMJ-Question.tsv"; sourceTree = "<group>"; };
08493A91245708B3002876D3 /* DataBase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataBase.swift; sourceTree = "<group>"; };
08493A9324570923002876D3 /* TestDataBase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestDataBase.swift; sourceTree = "<group>"; };
088F336A24601B58003B851D /* FileUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileUtils.swift; sourceTree = "<group>"; };
088F336D2460349D003B851D /* test_image.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = test_image.png; sourceTree = "<group>"; };
08F6191224586B21006E0233 /* SqliteDataBase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SqliteDataBase.swift; sourceTree = "<group>"; };
52963ABB2456C5020021AAE6 /* MapoFlowerIsland.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = MapoFlowerIsland.otf; sourceTree = "<group>"; };
52963ABF2456D4D70021AAE6 /* GyeonggiBatang.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = GyeonggiBatang.ttf; sourceTree = "<group>"; };
Expand Down Expand Up @@ -63,6 +67,7 @@
isa = PBXGroup;
children = (
08331E86245BEE6B001103A6 /* DateUtils.swift */,
088F336A24601B58003B851D /* FileUtils.swift */,
);
path = Utils;
sourceTree = "<group>";
Expand All @@ -77,6 +82,14 @@
path = DataBase;
sourceTree = "<group>";
};
088F336C24603466003B851D /* images */ = {
isa = PBXGroup;
children = (
088F336D2460349D003B851D /* test_image.png */,
);
path = images;
sourceTree = "<group>";
};
AE74448C2451CCE8000121F8 = {
isa = PBXGroup;
children = (
Expand All @@ -96,6 +109,7 @@
AE7444972451CCE8000121F8 /* OneDayOneAnswer */ = {
isa = PBXGroup;
children = (
088F336C24603466003B851D /* images */,
08331E8A245C2154001103A6 /* 42-JMJ-Question.tsv */,
08331E85245BEE3A001103A6 /* Utils */,
08493A9024570831002876D3 /* DataBase */,
Expand Down Expand Up @@ -180,6 +194,7 @@
AE7444A02451CCE8000121F8 /* Assets.xcassets in Resources */,
AE7444AB2451CD38000121F8 /* List.storyboard in Resources */,
52963AC02456D4D70021AAE6 /* GyeonggiBatang.ttf in Resources */,
088F336E2460349D003B851D /* test_image.png in Resources */,
AE74449E2451CCE8000121F8 /* Today.storyboard in Resources */,
08331E8B245C2154001103A6 /* 42-JMJ-Question.tsv in Resources */,
);
Expand All @@ -201,6 +216,7 @@
08F6191324586B21006E0233 /* SqliteDataBase.swift in Sources */,
AE7444AF2451CFCA000121F8 /* ListViewController.swift in Sources */,
08493A9424570923002876D3 /* TestDataBase.swift in Sources */,
088F336B24601B58003B851D /* FileUtils.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
8 changes: 2 additions & 6 deletions OneDayOneAnswer/OneDayOneAnswer/DataBase/SqliteDataBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,8 @@ class SqliteDataBase: DataBase {
}

private func initTable() -> Bool {
guard let fileURL: URL = Bundle.main.url(forResource: "42-JMJ-Question", withExtension: "tsv") else {
print("file not found")
return false
}
guard let contents: String = try? String(contentsOf: fileURL) else {
print("file could not be read")
guard let contents: String = getFileStringFromBundle(fileName: "42-JMJ-Question", fileExtension: "tsv") else {
print("question read error")
return false
}
var questions: [String] = []
Expand Down
42 changes: 42 additions & 0 deletions OneDayOneAnswer/OneDayOneAnswer/Utils/FileUtils.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// FileUtils.swift
// OneDayOneAnswer
//
// Created by Jaedoo Ko on 2020/05/04.
// Copyright © 2020 JMJ. All rights reserved.
//

import Foundation
import UIKit

func getUIImageFromDocDir(fileName: String) -> UIImage? {
guard let fileURL: URL = try? FileManager.default
.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false)
.appendingPathComponent(fileName) else {
print("image loading fail")
return nil
}
let image: UIImage? = UIImage(contentsOfFile: fileURL.path)
return image
}

func getUIImageFromBundle(fileName: String, fileExtension: String) -> UIImage? {
guard let fileURL: URL = Bundle.main.url(forResource: fileName, withExtension: fileExtension) else {
print("file not found")
return nil
}
let image: UIImage? = UIImage(contentsOfFile: fileURL.path)
return image
}

func getFileContentsFromBundle(fileName: String, fileExtension: String) -> String? {
guard let fileURL: URL = Bundle.main.url(forResource: fileName, withExtension: fileExtension) else {
print("file not found")
return nil
}
guard let str: String = try? String.init(contentsOf: fileURL) else {
print("file could not be read")
return nil
}
return str
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.