Tutorial by Examples: def

Combining typedef with struct can make code clearer. For example: typedef struct { int x, y; } Point; as opposed to: struct Point { int x, y; }; could be declared as: Point point; instead of: struct Point point; Even better is to use the following typedef struct Poin...
The android:process field defines the name of the process where the service is to run. Normally, all components of an application run in the default process created for the application. However, a component can override the default with its own process attribute, allowing you to spread your applicat...
Django manger is an interface through which the django model queries the database. The objects field used in most django queries is actually the default manager created for us by django (this is only created if we don't define custom managers). Why would we define a custom manager/queryset? To avo...
Predefined macros are those that the compiler defines (in contrast to those user defines in the source file). Those macros must not be re-defined or undefined by user. The following macros are predefined by the C++ standard: __LINE__ contains the line number of the line this macro is used on, an...
{ "name": "my-project", "version": "0.0.1", "description": "This is a project.", "author": "Someone <[email protected]>", "contributors": [{ "name": "Som...
By default, Interface Builder doesn't accept the CGColor datatype, so to allow adding a CGColor using user defined attributes in interface builder; one may want to use an extension like this: Swift Extension : extension CALayer { func borderUIColor() -> UIColor? { return borderCol...
References behaves similarly, but not entirely like const pointers. A reference is defined by suffixing an ampersand & to a type name. int i = 10; int &refi = i; Here, refi is a reference bound to i. References abstracts the semantics of pointers, acting like an alias to the underlying...
Letters 3.0 let letters = CharacterSet.letters let phrase = "Test case" let range = phrase.rangeOfCharacter(from: letters) // range will be nil if no letters is found if let test = range { print("letters found") } else { print("letters not found") }...
Glide includes two default transformations, fit center and center crop. Fit center: Glide.with(context) .load(yourUrl) .fitCenter() .into(yourView); Fit center performs the same transformation as Android's ScaleType.FIT_CENTER. Center crop: Glide.with(context) .load(yourUr...
The .GetValueOrDefault() method returns a value even if the .HasValue property is false (unlike the Value property, which throws an exception). class Program { static void Main() { int? nullableExample = null; int result = nullableExample.GetValueOrDefault(); C...
Simple check To check if constant is defined use the defined function. Note that this function doesn't care about constant's value, it only cares if the constant exists or not. Even if the value of the constant is null or false the function will still return true. <?php define("GOOD&quo...
Constants are created using the const statement or the define function. The convention is to use UPPERCASE letters for constant names. Define constant using explicit values const PI = 3.14; // float define("EARTH_IS_FLAT", false); // boolean const "UNKNOWN" = null; // null d...
A predefined macro is a macro that is already understood by the C pre processor without the program needing to define it. Examples include Mandatory Pre-Defined Macros __FILE__, which gives the file name of the current source file (a string literal), __LINE__ for the current line number (an int...
The typical example is an abstract shape class, that can then be derived into squares, circles, and other concrete shapes. The parent class: Let's start with the polymorphic class: class Shape { public: virtual ~Shape() = default; virtual double get_surface() const = 0; virtual vo...
Color state lists can be used as colors, but will change depending on the state of the view they are used for. To define one, create a resource file in res/color/foo.xml <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/ap...
Variables of character type or of a derived type with length parameter may have the length parameter either assumed or deferred. The character variable name character(len=len) name is of length len throughout execution. Conversely the length specifier may be either character(len=*) ... ! Ass...
for typescript 2.x: definitions from DefinitelyTyped are available via @types npm package npm i --save lodash npm i --save-dev @types/lodash but in case if you want use types from other repos then can be used old way: for typescript 1.x: Typings is an npm package that can automatically insta...
You can use an initializer to set default property values: struct Example { var upvotes: Int init() { upvotes = 42 } } let myExample = Example() // call the initializer print(myExample.upvotes) // prints: 42 Or, specify default property values as a part of the property...
An enum is a set of logically related constants. Enum Size Small Medium Large End Enum Public Sub Order(shirtSize As Size) Select Case shirtSize Case Size.Small ' ... Case Size.Medium ' ... Case Size.Large ' ....
Optional Parameters In TypeScript, every parameter is assumed to be required by the function. You can add a ? at the end of a parameter name to set it as optional. For example, the lastName parameter of this function is optional: function buildName(firstName: string, lastName?: string) { // ...

Page 5 of 27