Tutorial by Examples: e

std::async is also able to make threads. Compared to std::thread it is considered less powerful but easier to use when you just want to run a function asynchronously. Asynchronously calling a function #include <future> #include <iostream> unsigned int square(unsigned int i){ r...
If you want to pass in values to a method when it is called, you use parameters: - (int)addInt:(int)intOne toInt:(int)intTwo { return intOne + intTwo; } The colon (:) separates the parameter from the method name. The parameter type goes in the parentheses (int). The parameter name goes aft...
This is how to create a basic method that logs 'Hello World" to the console: - (void)hello { NSLog(@"Hello World"); } The - at the beginning denotes this method as an instance method. The (void) denotes the return type. This method doesn't return anything, so you enter void. ...
When you want to return a value from a method, you put the type you want to return in the first set of parentheses. - (NSString)returnHello { return @"Hello World"; } The value you want to return goes after the return keyword;
A class method is called on the class the method belongs to, not an instance of it. This is possible because Objective-C classes are also objects. To denote a method as a class method, change the - to a +: + (void)hello { NSLog(@"Hello World"); }
Calling an instance method: [classInstance hello]; @interface Sample -(void)hello; // exposing the class Instance method @end @implementation Sample -(void)hello{ NSLog(@"hello"); } @end Calling an instance method on the current instance: [self hell...
Abstract classes are classes that are meant to be inherited but avoid implementing specific methods, leaving behind only method signatures that subclasses must implement. Abstract classes are useful for defining and enforcing class abstractions at a high level, similar to the concept of interfaces ...
@implemenetation Triangle ... -(void)setAngles:(NSArray *)_angles { self.angles = _angles; NSAssert((self.angles.count == 3), @"Triangles must have 3 angles. Array '%@' has %i", self.angles, (int)self.angles.count); CGFloat angleA = [self.angles[0] floatVal...
A Broadcast receiver is an Android component which allows you to register for system or application events. A receiver can be registered via the AndroidManifest.xml file or dynamically via the Context.registerReceiver() method. public class MyReceiver extends BroadcastReceiver { @Override ...
The where method is available on any ActiveRecord model and allows querying the database for a set of records matching the given criteria. The where method accepts a hash where the keys correspond to the column names on the table that the model represents. As a simple example, we will use the foll...
The where method on any ActiveRecord model can be used to generate SQL of the form WHERE column_name IN (a, b, c, ...). This is achieved by passing an array as argument. As a simple example, we will use the following model: class Person < ActiveRecord::Base #attribute :first_name, :string ...
Scopes act as predefined filters on ActiveRecord models. A scope is defined using the scope class method. As a simple example, we will use the following model: class Person < ActiveRecord::Base #attribute :first_name, :string #attribute :last_name, :string #attribute :age, :integer ...
nuget sources add -name feedname -source http://sourcefeedurl
Unlike C++ in C# you can call a virtual method from class constructor (OK, you can also in C++ but behavior at first is surprising). For example: abstract class Base { protected Base() { _obj = CreateAnother(); } protected virtual AnotherBase CreateAnother() { ...
You can create a CALayer and set its frame like this: Swift: let layer = CALayer() layer.frame = CGRect(x: 0, y: 0, width: 60, height: 80) Objective-C: CALayer *layer = [[CALayer alloc] init]; layer.frame = CGRectMake(0, 0, 60, 80); You can then add it as a sublayer to an existing CALayer...
To add a method to a button, first create an action method: Objective-C -(void)someButtonAction:(id)sender { // sender is the object that was tapped, in this case its the button. NSLog(@"Button is tapped"); } Swift func someButtonAction() { print("Button is tapped...
You can easily transform every component in a clickable button using the MouseArea component. The code below displays a 360x360 window with a button and a text in the center; pressing the button will change the text: import QtQuick 2.0 Rectangle { width: 360 height: 360 Rectang...
To find all the files of a certain extension within the current path you can use the following find syntax. It works by making use of bash's built-in glob construct to match all the names having the .extension. find /directory/to/search -maxdepth 1 -type f -name "*.extension" To find ...
First try use pivot: import pandas as pd import numpy as np df = pd.DataFrame({'Name':['Mary', 'Josh','Jon','Lucy', 'Jane', 'Sue'], 'Age':[34, 37, 29, 40, 29, 31], 'City':['Boston','New York', 'Chicago', 'Los Angeles', 'Chicago', 'Boston'], ...
import pandas as pd import numpy as np df = pd.DataFrame({'Name':['Mary', 'Jon','Lucy', 'Jane', 'Sue', 'Mary', 'Lucy'], 'Age':[35, 37, 40, 29, 31, 26, 28], 'City':['Boston', 'Chicago', 'Los Angeles', 'Chicago', 'Boston', 'Boston', 'Chicago'], ...

Page 159 of 1191