[Swift-commit] r6258 - trunk/docs/userguide
ketan at ci.uchicago.edu
ketan at ci.uchicago.edu
Mon Feb 11 12:29:44 CST 2013
Author: ketan
Date: 2013-02-11 12:29:44 -0600 (Mon, 11 Feb 2013)
New Revision: 6258
Modified:
trunk/docs/userguide/app_procedures
trunk/docs/userguide/language
Log:
readData example
Modified: trunk/docs/userguide/app_procedures
===================================================================
--- trunk/docs/userguide/app_procedures 2013-02-11 17:24:40 UTC (rev 6257)
+++ trunk/docs/userguide/app_procedures 2013-02-11 18:29:44 UTC (rev 6258)
@@ -442,9 +442,36 @@
same order as the header row. For arrays of structs, the file should contain a
heading row listing structure member names separated by whitespace. There
should be one row for each element of the array, with structure member elements
-listed in the same order as the header row and separated by whitespace. (since
-Swift 0.4)
+listed in the same order as the header row and separated by whitespace. The following example shows how readData() can be used to populate an array of Swift struct-like complex type:
+----
+type Employee{
+ string name;
+ int id;
+ string loc;
+}
+
+Employee emps[] = readData("emps.txt");
+----
+
+Where the contents of the "emps.txt" file are:
+
+----
+name id address
+Thomas 2222 Chicago
+Gina 3333 Boston
+Anne 4444 Houston
+----
+
+This will result in the array "emps" with 3 members. This can be processed within a Swift script using the foreach construct as follows:
+
+----
+foreach emp in emps{
+ tracef("Employee %s lives in %s and has id %d", emp.name, emp.loc, emp.id);
+}
+----
+
+
readStructured
~~~~~~~~~~~~~~
readStructured will read data from a specified file, like readdata, but
Modified: trunk/docs/userguide/language
===================================================================
--- trunk/docs/userguide/language 2013-02-11 17:24:40 UTC (rev 6257)
+++ trunk/docs/userguide/language 2013-02-11 18:29:44 UTC (rev 6258)
@@ -40,7 +40,7 @@
type Employee{
string name;
int id;
- string address;
+ string loc;
}
----
@@ -51,7 +51,7 @@
Employee emp;
emp.name="Thomas";
emp.id=2222;
-emp.address="Chicago";
+emp.loc="Chicago";
----
Arrays of structures are allowed in Swift. A convenient way of populating
More information about the Swift-commit
mailing list