Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
0right0705 committed Feb 15, 2024
0 parents commit 72bbda4
Show file tree
Hide file tree
Showing 14 changed files with 921 additions and 0 deletions.
586 changes: 586 additions & 0 deletions AlwaysOnSize.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>AlwaysOnSize.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
</dict>
</plist>
5 changes: 5 additions & 0 deletions AlwaysOnSize/AlwaysOnSize.entitlements
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict/>
</plist>
81 changes: 81 additions & 0 deletions AlwaysOnSize/AlwaysOnSizeApp.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
//
// AlwaysOnSizeApp.swift
// AlwaysOnSize
//
// Created by 최영우 on 2024. 2. 14..
//

import SwiftUI
import CoreServices

@main
struct AlwaysOnSizeApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}

func getFormatedNumberString(size: Double) -> String {

var varsize : Double = size
if (varsize) / 1024 < 1 {
return String(format: "%.1fByte", varsize)
}
varsize /= 1024
if varsize / 1024 < 1 {
return String(format: "%.1fKB", varsize)
}
varsize /= 1024
if varsize / 1024 < 1 {
return String(format: "%.1fMB", varsize)
}
varsize /= 1024


return String(format: "%.1fGB", varsize)
}


func getFreeSizeAsString() -> String {

let documentDirectoryPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
var freeSize: Double? // Byte단위
do {
let attributes = try FileManager.default.attributesOfFileSystem(forPath: documentDirectoryPath.last! as String)
freeSize = attributes[FileAttributeKey.systemFreeSize] as? Double
} catch {
print(error)
}

var freeSizeAsDouble: Double = freeSize as? Double ?? 0
return getFormatedNumberString(size: freeSize!)
}


func findFileSize() -> String {
let filePath = try? FileManager.default.contentsOfDirectory(at: .downloadsDirectory, includingPropertiesForKeys: [.fileSizeKey])

var fileSize : Double = 0

do {
//return [FileAttributeKey : Any]
for file in filePath! {
print(file)

let attr = try FileManager.default.attributesOfItem(atPath: file.path)
fileSize = attr[FileAttributeKey.size] as! Double

//if you convert to NSDictionary, you can get file size old way as well.
let dict = attr as NSDictionary
fileSize = Double(dict.fileSize())
print(getFormatedNumberString(size: fileSize))
}
} catch {
print("Error: \(error)")
}
return getFormatedNumberString(size: fileSize)
}


11 changes: 11 additions & 0 deletions AlwaysOnSize/Assets.xcassets/AccentColor.colorset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
58 changes: 58 additions & 0 deletions AlwaysOnSize/Assets.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"images" : [
{
"idiom" : "mac",
"scale" : "1x",
"size" : "16x16"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "16x16"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "32x32"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "32x32"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "128x128"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "128x128"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "256x256"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "256x256"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "512x512"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "512x512"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
6 changes: 6 additions & 0 deletions AlwaysOnSize/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
30 changes: 30 additions & 0 deletions AlwaysOnSize/ContentView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// ContentView.swift
// AlwaysOnSize
//
// Created by 최영우 on 2024. 2. 14..
//

import SwiftUI

struct ContentView: View {
@State var name : String = ""
var storage : String = getFreeSizeAsString()
var size : String = findFileSize()
var body: some View {
VStack {
Image(systemName: "globe")
.imageScale(.large)
.foregroundStyle(.tint)
Text(storage)
Text(size)
}
.padding()
}
}

#Preview {
ContentView()
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
36 changes: 36 additions & 0 deletions AlwaysOnSizeTests/AlwaysOnSizeTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// AlwaysOnSizeTests.swift
// AlwaysOnSizeTests
//
// Created by 최영우 on 2024. 2. 14..
//

import XCTest
@testable import AlwaysOnSize

final class AlwaysOnSizeTests: XCTestCase {

override func setUpWithError() throws {
// Put setup code here. This method is called before the invocation of each test method in the class.
}

override func tearDownWithError() throws {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}

func testExample() throws {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
// Any test you write for XCTest can be annotated as throws and async.
// Mark your test throws to produce an unexpected failure when your test encounters an uncaught error.
// Mark your test async to allow awaiting for asynchronous code to complete. Check the results with assertions afterwards.
}

func testPerformanceExample() throws {
// This is an example of a performance test case.
self.measure {
// Put the code you want to measure the time of here.
}
}

}
41 changes: 41 additions & 0 deletions AlwaysOnSizeUITests/AlwaysOnSizeUITests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// AlwaysOnSizeUITests.swift
// AlwaysOnSizeUITests
//
// Created by 최영우 on 2024. 2. 14..
//

import XCTest

final class AlwaysOnSizeUITests: XCTestCase {

override func setUpWithError() throws {
// Put setup code here. This method is called before the invocation of each test method in the class.

// In UI tests it is usually best to stop immediately when a failure occurs.
continueAfterFailure = false

// In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this.
}

override func tearDownWithError() throws {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}

func testExample() throws {
// UI tests must launch the application that they test.
let app = XCUIApplication()
app.launch()

// Use XCTAssert and related functions to verify your tests produce the correct results.
}

func testLaunchPerformance() throws {
if #available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 7.0, *) {
// This measures how long it takes to launch your application.
measure(metrics: [XCTApplicationLaunchMetric()]) {
XCUIApplication().launch()
}
}
}
}
32 changes: 32 additions & 0 deletions AlwaysOnSizeUITests/AlwaysOnSizeUITestsLaunchTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// AlwaysOnSizeUITestsLaunchTests.swift
// AlwaysOnSizeUITests
//
// Created by 최영우 on 2024. 2. 14..
//

import XCTest

final class AlwaysOnSizeUITestsLaunchTests: XCTestCase {

override class var runsForEachTargetApplicationUIConfiguration: Bool {
true
}

override func setUpWithError() throws {
continueAfterFailure = false
}

func testLaunch() throws {
let app = XCUIApplication()
app.launch()

// Insert steps here to perform after app launch but before taking a screenshot,
// such as logging into a test account or navigating somewhere in the app

let attachment = XCTAttachment(screenshot: app.screenshot())
attachment.name = "Launch Screen"
attachment.lifetime = .keepAlways
add(attachment)
}
}

0 comments on commit 72bbda4

Please sign in to comment.