You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: issue-12/iOS8 Swift文件管理教程.md
+5-36Lines changed: 5 additions & 36 deletions
Original file line number
Diff line number
Diff line change
@@ -8,63 +8,47 @@ iOS8 Swift文件管理教程
8
8
* 校对者: [这里校对者的github用户名](github链接)
9
9
* 状态 : 未完成 / 校对中 / 完成
10
10
11
-
When an iOS App is installed on a device, a folder structure will be created, including a tmp directory for storing temporary data. In this tutorial we are managing files in this tmp directory such as creating, reading and deleting files. This tutorial is built in iOS 8.1 with Xcode 6.1.
Open Xcode and create a new Single View Application. For product name, use IOS8SwiftFileManagementTutorial and then fill out the Organization Name and Organization Identifier with your customary values. Enter Swift as Language and make sure only iPhone is selected in Devices.
Select all items by holding the Ctrl-key and select the "Resolve Auto Layout Issues" button at the bottom-right(3rd button) and select Add Missing Constraints.
36
28
37
-
通过按住Ctrl键选择全部,然后点击在底部的第三个按钮选择`Resolve Auto Layout Issues`来添加缺少的约束。
29
+
通过按住Ctrl键选择全部按钮,然后点击在底部的第三个按钮选择`Resolve Auto Layout Issues`来添加缺少的约束。
The buttons will be placed below and next to each other, even when the device rotates. Select the Assistant Editor and make sure the ViewController.swift is visible. Ctrl and drag from the "Create File" Button to the ViewController class and create the following Action.
Go to the ViewController.swift file and add the following properties to the ViewController class
67
-
68
52
在`ViewController.swift`文件中添加下列属性。
69
53
70
54
```
@@ -73,15 +57,10 @@ var tmpDir = NSTemporaryDirectory()
73
57
let fileName = "sample.txt"
74
58
```
75
59
76
-
* The NSFileManager class lets you examine the contents of the filesystem and make changes to it.
77
-
* The NSTemporaryDirectory is a temporary directory for the current user
78
-
* A file with a filename of "sample.txt" will be used for this tutorial
79
-
80
60
*`NSFileManager `类让你查看文件系统的内容并改变它。
81
-
*`NSTemporaryDirectory `是一个当前用户的临时文件夹
61
+
*`NSTemporaryDirectory `是当前用户的一个临时文件夹
82
62
* "sample.txt"文件将在本教程中用到
83
63
84
-
Before the Action methods will be implemented a helper method enumerateDirectory will be created, which will be used to check for files inside a directory.
All files inside the temporary directory will be put into a array of type String and this array will be checked for the existence of our sample.txt file. When succesful, the filename will be returned, otherwise nil will be returned. Next, implement the createFile method.
@@ -128,8 +105,6 @@ All files inside the temporary directory will be put into a array of type String
128
105
}
129
106
```
130
107
131
-
The sample.txt file is created with some content and written to the tmp directory with the writeToFile:atomically:encoding:error method. When this actions fails. an error message will be printed to the console. Next, implement the listDirectory method.
@@ -141,7 +116,6 @@ The sample.txt file is created with some content and written to the tmp director
141
116
}
142
117
```
143
118
144
-
The enumerateDirectory method is called, when there is no file present in the directory the "Empty" string is assigned to the isFileInDir variable. the ?? operator is the nil coalescing operator which evaluates an expression (enumerateDirectory() ) When true the optional value will be unwrapped, when false a default value will be returned ( "Empty" string). The Contents of the directory will be printed to the console. Next, implement the viewFileContent method.
@@ -160,8 +134,6 @@ The enumerateDirectory method is called, when there is no file present in the di
160
134
}
161
135
```
162
136
163
-
The contentsOfFile:encoding:error method puts the content of a file into a NSString. If the file is present, the content will be printed to the console, otherwise the "No file found" message will be printed to the console. Finally, implement the deleteFile method
@@ -177,12 +149,9 @@ The contentsOfFile:encoding:error method puts the content of a file into a NSStr
177
149
}
178
150
```
179
151
180
-
The removeItemAtPath:error method deletes the file. Build and Run the project, select the buttons and look at the console to see the results of each action.
0 commit comments