Tutorial by Examples: c

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 ...
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 ...
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 ...
Since Git 1.7.12 it is possible to rebase down to the root commit. The root commit is the first commit ever made in a repository, and normally cannot be edited. Use the following command: git rebase -i --root
Note that you cannot overload a function based on its return type. For example: // WRONG CODE std::string getValue() { return "hello"; } int getValue() { return 0; } int x = getValue(); This will cause a compilation error as the compiler will not be able to work out wh...
It is also possible to write a context manager using generator syntax thanks to the contextlib.contextmanager decorator: import contextlib @contextlib.contextmanager def context_manager(num): print('Enter') yield num + 1 print('Exit') with context_manager(2) as cm: # the ...
Intents can be used to broadcast messages to other components of your application (such as a running background service) or to the entire Android system. To send a broadcast within your application, use the LocalBroadcastManager class: Intent intent = new Intent("com.example.YOUR_ACTION"...
This code selects data out of a table and displays it in the query tool (usually SSMS) SELECT Column1, Column2, Column3 FROM MySourceTable; This code inserts that data into a table: INSERT INTO MyTargetTable (Column1, Column2, Column3) SELECT Column1, Column2, Column3 FROM MySourceTable;
This code selects data out of a table: SELECT Column1, Column2, Column3 FROM MySourceTable; This code creates a new table called MyNewTable and puts that data into it SELECT Column1, Column2, Column3 INTO MyNewTable FROM MySourceTable;
@interface Dog : RLMObject @property NSString *name; @property NSInteger age; @end @implementation Dog @end Dog *dog = [Dog new]; dog.name = @"Rex"; dog.age = 1; RLMRealm *realm = [RLMRealm defaultRealm]; [realm transactionWithBlock:^{ [realm addObject:dog]; }]; RLMR...
class Dog {} Dog.schema = { name: 'Dog', properties: { name: 'string', age: 'int', } }; let realm = new Realm(); realm.write(() => { realm.create('Dog', {name: 'Rex', age: 1}); }); let pups = realm.objects('Dog').filtered('age > 2');
Since C# 6.0 exceptions can be filtered using the when operator. This is similar to using a simple if but does not unwind the stack if the condition inside the when is not met. Example try { // ... } catch (Exception e) when (e.InnerException != null) // Any condition can go in here. { ...

Page 111 of 826