Tutorial by Examples

Detailed instructions on getting date set up or installed.
package { import flash.events.TimerEvent; import flash.utils.Timer; public class CountdownTimer extends Timer { public var time:Number = 0; public function CountdownTimer(time:Number = Number.NEGATIVE_INFINITY, delay:Number = 1000) { super(delay, repeatCount); ...
Using functions that take in and execute closures can be extremely useful for sending a block of code to be executed elsewhere. We can start by allowing our function to take in an optional closure that will (in this case) return Void. func closedFunc(block: (()->Void)? = nil) { print("...
Note: Everything below applies to the str.format method, as well as the format function. In the text below, the two are interchangeable. For every value which is passed to the format function, Python looks for a __format__ method for that argument. Your own custom class can therefore have th...
// RawRepresentable has an associatedType RawValue. // For this struct, we will make the compiler infer the type // by implementing the rawValue variable with a type of String // // Compiler infers RawValue = String without needing typealias // struct NotificationName: RawRepresentable { ...
A protocol may specify that only a class can implement it through using the class keyword in its inheritance list. This keyword must appear before any other inherited protocols in this list. protocol ClassOnlyProtocol: class, SomeOtherProtocol { // Protocol requirements } If a non-class typ...
3.0 Swift 3 introduces the CountedSet class (it's the Swift version of the NSCountedSet Objective-C class). CountedSet, as suggested by the name, keeps track of how many times a value is present. let countedSet = CountedSet() countedSet.add(1) countedSet.add(1) countedSet.add(1) countedSet.a...
Select the .xcdatamodeld file. You will notice you have no entities. You will have to create one yourself. At the bottom of Xcode you will notice a button that says "Add Entity" click it and you will have a new entity for you to work with on the project. In this step there are ...
With Gson, you can read JSON dataset and map them to a custom class MyClass. Since Gson is not serializable, each executor needs its own Gson object. Also, MyClass must be serializable in order to pass it between executors. Note that the file(s) that is offered as a json file is not a typical JSON...
We define the type of boolean expressions whose atoms are identified by strings as type expr = | Atom of string | Not of expr | And of expr * expr | Or of expr * expr and can evaluate these expressions using an oracle : string -> bool giving the values of the atoms we find as follows: le...
Pattern matching allows to deconstruct complex values and it is by no way limited to the “outer most” level of the representation of a value. To illustrate this, we implement the function transforming a boolean expression into a boolean expression where all negations are only on atoms, the so calle...
Pattern matching can be used to deconstruct records. We illustrate this with a record type representing locations in a text file, e.g. the source code of a program. type location = { filename : string; line: int; column: int; offset: int; } A value x of type location can be deconstr...
We prepare a file called reverser.ml with the following contents: let acc = ref [] in try while true do acc := read_line () :: !acc; done with End_of_file -> print_string (String.concat "\n" !acc) We then compile our program using ...
The List.fold_left and List.fold_right functions are higher-order functions that implement the outer logic of list aggregation. Aggregating a list, sometimes also referred to as reducing a list, means computing a value derived from the sequential inspection of all items in that list. The documenta...
final TextView mTextView = (TextView) findViewById(R.id.text); ... // Instantiate the RequestQueue. RequestQueue queue = Volley.newRequestQueue(this); String url ="http://www.google.com"; // Request a string response from the provided URL. StringRequest stringRequest = new String...
// assume a Request and RequestQueue have already been initialized somewhere above public static final String TAG = "SomeTag"; // Set the tag on the request. request.setTag(TAG); // Add the request to the RequestQueue. mRequestQueue.add(request); // To cancel this specific re...
There are several additional attributes that the Volley NetworkImageView adds to the standard ImageView. However, these attributes can only be set in code. The following is an example of how to make an extension class that will pick up the attributes from your XML layout file and apply them to the N...
final TextView mTxtDisplay = (TextView) findViewById(R.id.txtDisplay); ImageView mImageView; String url = "http://ip.jsontest.com/"; final JsonObjectRequest jsObjRequest = new JsonObjectRequest (Request.Method.GET, url, null, new Response.Listener<JSONObject>() { ...
In Elm, reducing functions are called "folds", and there are two standard methods to "fold" values up: from the left, foldl, and from the right, foldr. > List.foldl (+) 0 [1,2,3] 6 : number The arguments to foldl and foldr are: reducing function: newValue -> accumul...
A reference to an option &Option<T> cannot be unwrapped if the type T is not copyable. The solution is to change the option to &Option<&T> using as_ref(). Rust forbids transferring of ownership of objects while the objects are borrowed. When the Option itself is borrowed (&a...

Page 360 of 1336