Skip to content

Commit 35e7112

Browse files
author
ChenHao
committed
修改错误 去除中文
1 parent ff209e3 commit 35e7112

File tree

1 file changed

+5
-36
lines changed

1 file changed

+5
-36
lines changed

issue-12/iOS8 Swift文件管理教程.md

Lines changed: 5 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,63 +8,47 @@ iOS8 Swift文件管理教程
88
* 校对者: [这里校对者的github用户名](github链接)
99
* 状态 : 未完成 / 校对中 / 完成
1010

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.
1211

13-
当一款iOS的App安装到设备上以后,将会创建一个文件结构,包含了用于存储临时文件的临时文件夹。这篇文章我们来讲解在临时文件夹中管理文件,包括创建读取和删除。教程基于iOS8.1和Xcode6.1
14-
15-
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.
12+
当一款iOS的App安装到设备上以后,将会创建一个文件夹,其中包含了用于存储临时文件的临时文件夹。这篇文章我们在管理该临时文件夹,包括创建读取和删除文件。教程基于iOS8.1和Xcode6.1
1613

1714
打开Xcode创建一个新的`Single View Application`项目,以`IOS8SwiftFileManagementTutorial `作为项目的名称,填写组织名称和组织标识符。选择Swift语言,确保Devices为iPhone。
1815

1916
![](http://static1.squarespace.com/static/52428a0ae4b0c4a5c2a2cede/t/54f8bc03e4b0d007a6fee8a4/1425587211870/?format=1500w)
2017

21-
Go to the Storyboard and drag four Buttons to the main View. Give the buttons the following titles.
22-
2318
在故事版中拖四个按钮到主视图中,名称分别为以下:
2419

2520
* Create File
2621
* List Directory
2722
* View File Content
2823
* Delete File
2924

30-
31-
The Storyboard will look like this.
3225
故事版看起来像这样
3326
![](http://static1.squarespace.com/static/52428a0ae4b0c4a5c2a2cede/t/54f8d8bfe4b00d102a265006/1425594560844/?format=1500w)
3427

35-
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.
3628

37-
通过按住Ctrl键选择全部,然后点击在底部的第三个按钮选择`Resolve Auto Layout Issues`来添加缺少的约束。
29+
通过按住Ctrl键选择全部按钮,然后点击在底部的第三个按钮选择`Resolve Auto Layout Issues`来添加缺少的约束。
3830
![](http://static1.squarespace.com/static/52428a0ae4b0c4a5c2a2cede/t/54f8d98ce4b070bffa96534e/1425594775771/?format=750w)
3931

40-
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.
41-
4232
按钮依次放置,即使在设备旋转的时候,选择`Assistant Editor`并让ViewController.swift可见。按住Ctrl将`Create File`拖到`ViewController `类,创建以下动作。
4333

4434
![](http://static1.squarespace.com/static/52428a0ae4b0c4a5c2a2cede/t/54fb76ade4b03452415dab06/1425766065262/?format=750w)
4535

46-
Ctrl and drag from the "List Directory" Button to the ViewController class and create the following Action.
4736

4837
按住Ctrl将`List Directory`拖到`ViewController `类,创建以下动作。
4938

5039
![](http://static1.squarespace.com/static/52428a0ae4b0c4a5c2a2cede/t/54fb7951e4b0f473c20ec908/1425766739551/listFile-Action.png?format=750w)
5140

5241

53-
Ctrl and drag from the "View File Content" Button to the ViewController class and create the following Action.
54-
5542
按住Ctrl将`View File Content`拖到`ViewController `类,创建以下动作。
5643

5744
![](http://static1.squarespace.com/static/52428a0ae4b0c4a5c2a2cede/t/54fb7989e4b0edea6489289e/1425766794964/?format=750w)
5845

59-
Ctrl and drag from the "Delete File" Button to the ViewController class and create the following Action.
6046

6147
按住Ctrl将`Delete File`拖到`ViewController `类,创建以下动作。
6248

6349
![](http://static1.squarespace.com/static/52428a0ae4b0c4a5c2a2cede/t/54fb7a06e4b0ecb31a5b46ea/1425766920438/?format=750w)
6450

6551

66-
Go to the ViewController.swift file and add the following properties to the ViewController class
67-
6852
`ViewController.swift`文件中添加下列属性。
6953

7054
```
@@ -73,15 +57,10 @@ var tmpDir = NSTemporaryDirectory()
7357
let fileName = "sample.txt"
7458
```
7559

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-
8060
* `NSFileManager `类让你查看文件系统的内容并改变它。
81-
* `NSTemporaryDirectory `是一个当前用户的临时文件夹
61+
* `NSTemporaryDirectory `是当前用户的一个临时文件夹
8262
* "sample.txt"文件将在本教程中用到
8363

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.
8564

8665
在动作方法实现之前先创建一个`enumerateDirectory`方法用来检查文件是否存在。
8766

@@ -106,9 +85,7 @@ func enumerateDirectory() -> String? {
10685
10786
```
10887

109-
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.
110-
111-
临时文件夹中的所有文件将被放在一个字符串的数组中,这个数组将被用来检查sample.txt是否存在。如果存在,文件名会被返回。反则返回nil。接着实现文件创建方法。
88+
临时文件夹中的所有文件将被放在一个字符串的数组中,这个数组将被用来检查sample.txt是否存在。如果存在,文件名会被返回。否则返回nil。接着实现文件创建方法。
11289

11390
```
11491
@IBAction func createFile(sender: AnyObject) {
@@ -128,8 +105,6 @@ All files inside the temporary directory will be put into a array of type String
128105
}
129106
```
130107

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.
132-
133108
使用`writeToFile:atomically:encoding:error`将sample.txt被创建并写到临时文件夹中。如果失败,一个错误信息会被打印到控制台。接下来实现`listDirectory `方法。
134109

135110

@@ -141,7 +116,6 @@ The sample.txt file is created with some content and written to the tmp director
141116
}
142117
```
143118

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.
145119

146120
`enumerateDirectory `被调用,当没有文件存在的时候将`isFileInDir `赋值为`Empty`。??操作符用来判断表达式`(enumerateDirectory() )`是否为nil,当为真的时候可选变量会被拆包。当为假的时候会有默认值"Empty",文件夹的内容会被打印到控制台。接下来实现`viewFileContent `方法。
147121

@@ -160,8 +134,6 @@ The enumerateDirectory method is called, when there is no file present in the di
160134
}
161135
```
162136

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
164-
165137
`contentsOfFile:encoding:error`方法将文件内容放在一个字符串中。如果文件存在,将会被打印到控制台,如果不存在,将会打印'No file found'消息。最后来实现`deleteFile `方法。
166138

167139
```
@@ -177,12 +149,9 @@ The contentsOfFile:encoding:error method puts the content of a file into a NSStr
177149
}
178150
```
179151

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.
181-
182-
`removeItemAtPath:error`方法用来删除文件,编译并运行工程,选择按钮来观察控制台输出。
152+
`removeItemAtPath:error`方法用来删除文件,编译并运行工程,选择`console`按钮来查看控制台输出。
183153

184154
![](http://static1.squarespace.com/static/52428a0ae4b0c4a5c2a2cede/t/54fb82f2e4b03edc59f68802/1425769204078/?format=1000w)
185155

186-
You can download the source code of the IOS8SwiftFileManagementTutorial at the ioscreator repository on Github.
187156

188157
你可以在GitHub下载源码[IOS8SwiftFileManagementTutorial](https://github.com/ioscreator/ioscreator)

0 commit comments

Comments
 (0)