File
Properties
| Name | Description | Type | Default |
|---|
| currentPath | URL ตั้งต้นสำหรับการจัดการเกี่ยวกับไฟล์ทั้งหมด | Optional(URL) | Document Directory ของเครื่อง |
Method Overview
| Name | Description | Return |
|---|
| writeImage() | การเขียนไฟล์ภาพ | Optional(URL) |
| writeData() | การเขียนไฟล์จาก Data | Optional(URL) |
| writeFile() | การเขียนไฟล์จาก Text | Optional(URL) |
| writeFileWithJson() | การเขียนไฟล์จาก Json | Optional(URL) |
| createDirectory() | การสร้าง Directory | Optional(URL) |
| zipFile() | การสร้าง ZIP File | Optional(URL) |
| getData() | การอ่านไฟล์จาก URL | Data |
| fileExists() | การตรวจสอบไฟล์ว่ามีอยู่แล้วหรือไม่ | Boolean |
| removeFile() | การลบไฟล์จาก URL | void |
| getAllFiles() | การดึงไฟล์ทั้งหมดจาก URL | Optional(FileManager.DirectoryEnumerator) |
Method Details
static func writeImage(fileName: String, fileType: ImageFileType, imagePath: URL, path: URL) -> URL?
การเขียนไฟล์ภาพจาก URL
Parameters
| Name | Description | Type |
|---|
| fileName | ชื่อของไฟล์ภาพที่ต้องการเขียน | String |
| fileType | ประเภทของไฟล์ภาพ | ImageFileType |
| imagePath | URL จากภาพที่ต้องการเขียน | URL |
| path | URL ของไฟล์ภาพที่เขียนขึ้นใหม่ | URL |
Returns
| Type | Description |
|---|
| Optional(URL) | Return URL ไฟล์ภาพที่เขียนขึ้นใหม่ |
static func writeImage(fileName: String, fileType: ImageFileType, image: UIImage, path: URL) -> URL?
การเขียนไฟล์ภาพจาก UIImage
Parameters
| Name | Description | Type |
|---|
| fileName | ชื่อของไฟล์ภาพที่ต้องการเขียน | String |
| fileType | ประเภทของไฟล์ภาพ | ImageFileType |
| image | ภาพที่ต้องการเขียน | UIImage |
| path | URL ของไฟล์ภาพที่เขียนขึ้นใหม่ | URL |
Returns
| Type | Description |
|---|
| Optional(URL) | Return URL ไฟล์ภาพที่เขียนขึ้นใหม่ |
static func writeData(fileName: String, data: Data, path: URL) -> URL?
การเขียนไฟล์จาก Data
Parameters
| Name | Description | Type |
|---|
| fileName | ชื่อของไฟล์ภาพที่ต้องการเขียน | String |
| data | ข้อมูลที่ต้องการเขียน | Data |
| path | URL ของไฟล์ที่เขียนขึ้นใหม่ | URL |
Returns
| Type | Description |
|---|
| Optional(URL) | Return URL ไฟล์ที่เขียนขึ้นใหม่ |
static func writeFile(text: String, fileName: String, path: URL) -> URL?
การเขียนไฟล์จาก Text
Parameters
| Name | Description | Type |
|---|
| text | ข้อความที่ต้องการเขียน | String |
| fileName | ชื่อของไฟล์ภาพที่ต้องการเขียน | String |
| path | URL ของไฟล์ที่เขียนขึ้นใหม่ | URL |
Returns
| Type | Description |
|---|
| Optional(URL) | Return URL ไฟล์ที่เขียนขึ้นใหม่ |
static func writeFileWithJson(json: Any, fileName: String, path: URL) -> URL?
การเขียนไฟล์จาก Json
Parameters
| Name | Description | Type |
|---|
| json | Json ที่ต้องการเขียน | Any |
| fileName | ชื่อของไฟล์ภาพที่ต้องการเขียน | String |
| path | URL ของไฟล์ที่เขียนขึ้นใหม่ | URL |
Returns
| Type | Description |
|---|
| Optional(URL) | Return URL ไฟล์ที่เขียนขึ้นใหม่ |
static func createDirectory(name: String, path: URL) -> URL?
การสร้าง Directory
Parameters
| Name | Description | Type |
|---|
| name | ชื่อของ Directory ที่ต้องการสร้าง | String |
| path | URL ของไฟล์ที่เขียนขึ้นใหม่ | URL |
Returns
| Type | Description |
|---|
| Optional(URL) | Return URL Directory ที่สร้างขึ้นใหม่ |
static func zipFile(srcPath: URL, desPath: URL) -> URL?
การสร้าง ZIP File
Parameters
| Name | Description | Type |
|---|
| srcPath | URL ของไฟล์ที่ต้องการ ZIP | URL |
| desPath | URL ของไฟล์ ZIP | URL |
Returns
| Type | Description |
|---|
| Optional(URL) | Return URL ไฟล์ ZIP ที่สร้างขึ้นใหม่ |
static func getData(withURL url: URL) -> Data
การอ่านไฟล์จาก URL
Parameters
| Name | Description | Type |
|---|
| withURL | URL ของไฟล์ที่ต้องการอ่าน | URL |
Returns
| Type | Description |
|---|
| Data | Return Data จากไฟล์ที่อ่าน |
static func fileExists(url: URL) -> Bool
การตรวจสอบไฟล์ว่ามีอยู่แล้วหรือไม่
Parameters
| Name | Description | Type |
|---|
| url | URL ของไฟล์ที่ต้องการตรวจสอบ | URL |
Returns
| Type | Description |
|---|
| Boolean | Return true เมื่อพบไฟล์ที่ตรวจสอบและ Return false เมื่อไม่พบไฟล์ที่ตรวจสอบ |
static func removeFile(url: URL)
การลบไฟล์จาก URL
Parameters
| Name | Description | Type |
|---|
| url | URL ของไฟล์ที่ต้องการลบ | URL |
static func getAllFiles(url: URL) -> FileManager.DirectoryEnumerator?
การดึงไฟล์ทั้งหมดจาก URL
Parameters
| Name | Description | Type |
|---|
| url | URL ที่ต้องการดึงไฟล์ทั้งหมด | URL |
Returns
| Type | Description |
|---|
| Optional(FileManager.DirectoryEnumerator) | Enumerator ของไฟล์ทั้งหมด |