Tutorial by Examples: ce

In iOS 8 Apple introduced the self sizing cell. Layout your UITableViewCells with Autolayout explicitly and UITableView takes care of the rest for you. Row height is calculated automatically, by default rowHeight value is UITableViewAutomaticDimension. UITableView property estimatedRowHeight is use...
Static method can be inherited similar to normal methods, however unlike normal methods it is impossible to create "abstract" methods in order to force static method overriding. Writing a method with the same signature as a static method in a super class appears to be a form of overriding,...
The most common uses of #include preprocessing directives are as in the following: #include <stdio.h> #include "myheader.h" #include replaces the statement with the contents of the file referred to. Angle brackets (<>) refer to header files installed on the system, while q...
The simplest form of macro replacement is to define a manifest constant, as in #define ARRSIZE 100 int array[ARRSIZE]; This defines a function-like macro that multiplies a variable by 10 and stores the new value: #define TIMES10(A) ((A) *= 10) double b = 34; int c = 23; TIMES10(b); //...
Classes are reference types, meaning that multiple variables can refer to the same instance. class Dog { var name = "" } let firstDog = Dog() firstDog.name = "Fido" let otherDog = firstDog // otherDog points to the same Dog instance otherDog.name = "Rover" // modifying otherDog also...
In MATLAB, the most basic data type is the numeric array. It can be a scalar, a 1-D vector, a 2-D matrix, or an N-D multidimensional array. % a 1-by-1 scalar value x = 1; To create a row vector, enter the elements inside brackets, separated by spaces or commas: % a 1-by-4 row vector v = [1, 2...
2.3 The Percent Support Library provides PercentFrameLayout and PercentRelativeLayout, two ViewGroups that provide an easy way to specify View dimensions and margins in terms of a percentage of the overall size. You can use the Percent Support Library by adding the following to your dependencies. ...
When working with dictionaries, it's often necessary to access all the keys and values in the dictionary, either in a for loop, a list comprehension, or just as a plain list. Given a dictionary like: mydict = { 'a': '1', 'b': '2' } You can get a list of keys using the keys() method: ...
Print element at index 0 echo "${array[0]}" 4.3 Print last element using substring expansion syntax echo "${arr[@]: -1 }" 4.3 Print last element using subscript syntax echo "${array[-1]}" Print all elements, each quoted separately echo "${array[@...
from collections import Counter c = Counter(["a", "b", "c", "d", "a", "b", "a", "c", "d"]) c # Out: Counter({'a': 3, 'b': 2, 'c': 2, 'd': 2}) c["a"] # Out: 3 c[7] # not in the list (7 oc...
alist = [1, 2, 3, 4, 1, 2, 1, 3, 4] alist.count(1) # Out: 3 atuple = ('bear', 'weasel', 'bear', 'frog') atuple.count('bear') # Out: 2 atuple.count('fox') # Out: 0
astring = 'thisisashorttext' astring.count('t') # Out: 4 This works even for substrings longer than one character: astring.count('th') # Out: 1 astring.count('is') # Out: 2 astring.count('text') # Out: 1 which would not be possible with collections.Counter which only counts single char...
(Note: All examples using let are also valid for const) var is available in all versions of JavaScript, while let and const are part of ECMAScript 6 and only available in some newer browsers. var is scoped to the containing function or the global space, depending when it is declared: var x = 4; /...
Java SE 7 As the try-catch-final statement example illustrates, resource cleanup using a finally clause requires a significant amount of "boiler-plate" code to implement the edge-cases correctly. Java 7 provides a much simpler way to deal with this problem in the form of the try-with-res...
Final classes When used in a class declaration, the final modifier prevents other classes from being declared that extend the class. A final class is a "leaf" class in the inheritance class hierarchy. // This declares a final class final class MyFinalClass { /* some code */ } ...
Replace by position To replace a portion of a std::string you can use the method replace from std::string. replace has a lot of useful overloads: //Define string std::string str = "Hello foo, bar and world!"; std::string alternate = "Hello foobar"; //1) str.replace(6, 3,...
There are several ways to extract characters from a std::string and each is subtly different. std::string str("Hello world!"); operator[](n) Returns a reference to the character at index n. std::string::operator[] is not bounds-checked and does not throw an exception. The caller is...
in myapp/context_processors.py: from django.conf import settings def debug(request): return {'DEBUG': settings.DEBUG} in settings.py: TEMPLATES = [ { ... 'OPTIONS': { 'context_processors': [ ... 'myapp.context_processor...
A C++ namespace is a collection of C++ entities (functions, classes, variables), whose names are prefixed by the name of the namespace. When writing code within a namespace, named entities belonging to that namespace need not be prefixed with the namespace name, but entities outside of it must use t...
Creating a namespace is really easy: //Creates namespace foo namespace Foo { //Declares function bar in namespace foo void bar() {} } To call bar, you have to specify the namespace first, followed by the scope resolution operator ::: Foo::bar(); It is allowed to create one names...

Page 7 of 134