Programming tuple spaces with Swift
You need an IDE, "xCode" by Apple has been used in this manual.
To import the SwiftSpace into xCode, you can simply double click the "SwiftSpace.xcodeproj" file.
- TupleSpace creation:
let albero = TupleSpace(TupleTree())
- SpaceRepository creation with a Space (named "Albero") and a gate:
let rep = SpaceRepository()
do {
try rep.add("Albero", albero)
} catch {
print("Error \(error)")
}
rep.addGate("tcp://192.168.1.68:9090/?keep")
- RemoteSpace creation:
let remote = RemoteSpace("tcp://80.182.103.158:9091/space?keep")
- How to create a template and perform a match on a tuple
let template = ["Hello World", FormalTemplateField(Int.self), 5] as [TemplateField]
template.match(tuple)
- Actions on a space
The framework contains the following tuple space operation and the syntax of them looks as follows
put([x1, x2, ..., xn])
get([x1, x2, ..., xn])
getp([x1, x2, ..., xn])
getAll([x1, x2, ..., xn])
getAll()
query([x1, x2, ..., xn])
queryp([x1, x2, ..., xn])
queryAll([x1, x2, ..., xn])
queryAll()
Example:
remote.put([5, true])
From xCode: Product->Scheme->SwiftSpaceTests
Now open a test inside the SwiftSpaceTest folder, and click the diamond (near the name of the class) that indicates the run.
Copy the content of the class you want to run (inside the "Examples" folder) as the main project.