Tutorial by Examples: c

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...
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...
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...
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...
There are some ways to break or change a loop's flow. break; will exit the current loop, and will not execute any more lines within that loop. continue; will not execute any more code within the current iteration of the loop, but will remain in the loop. The following loop will execute 101 times ...
Type casting is done with either the as operator: var chair:Chair = furniture as Chair; Or by wrapping the value in Type(): var chair:Chair = Chair(furniture); If the cast fails with as, the result of that cast is null. If the cast fails by wrapping in Type(), a TypeError is thrown.
Functions are of the type Function: function example():void { } trace(example is Function); // true They can be referenced by other variables with the type Function: var ref:Function = example; ref(); // ref.call(), ref.apply(), etc. And they can be passed in as arguments for parameters wh...
References to class declarations are typed Class: var spriteClass:Class = Sprite; You can use variables typed Class to instantiate instances of that class: var sprite:Sprite = new spriteClass(); This can be useful for passing an argument of type Class to a function that might create and inst...
You can use the is operator to validate whether a value is of a certain type: var sprite:Sprite = new Sprite(); trace(sprite is Sprite); // true trace(sprite is DisplayObject); // true, Sprite inherits DisplayObject trace(sprite is IBitmapDrawable); // true, DisplayObject implements IBitmapDra...
The C++ approach - new and delete In a language like C++, the application program is responsible for managing the memory used by dynamically allocated memory. When an object is created in the C++ heap using the new operator, there needs to be a corresponding use of the delete operator to dispose o...
3 You can use rem defined by the font-size of your html tag to style elements by setting their font-size to a value of rem and use em inside the element to create elements that scale with your global font-size. HTML: <input type="button" value="Button"> <input type=...
localStorage.length property returns an integer number indicating the number of elements in the localStorage Example: Set Items localStorage.setItem('StackOverflow', 'Documentation'); localStorage.setItem('font', 'Helvetica'); localStorage.setItem('image', 'sprite.svg'); Get length localSto...
Declare the AppWidgetProvider class in your application's AndroidManifest.xml file. For example: <receiver android:name="ExampleAppWidgetProvider" > <intent-filter> <action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> </intent-filter&gt...
The most important AppWidgetProvider callback is onUpdate(). It is called everytime an appwidget is added. public class ExampleAppWidgetProvider extends AppWidgetProvider { public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { final int N = a...

Page 220 of 826