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 ...
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()
{
...
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...
Filters can either be defined in a method and then added to Jinja's filters dictionary, or defined in a method decorated with Flask.template_filter.
Defining and registering later:
def format_datetime(value, format="%d %b %Y %I:%M %p"):
"""Format a date time to (Defau...
TRUNCATE TABLE Employee;
Using truncate table is often better then using DELETE TABLE as it ignores all the indexes and triggers and just removes everything.
Delete table is a row based operation this means that each row is deleted. Truncate table is a data page operation the entire data page is...
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;
To move data you first insert it into the target, then delete whatever you inserted from the source table. This is not a normal SQL operation but it may be enlightening
What did you insert? Normally in databases you need to have one or more columns that you can use to uniquely identify rows so we w...
Within a catch block the throw keyword can be used on its own, without specifying an exception value, to rethrow the exception which was just caught. Rethrowing an exception allows the original exception to continue up the exception handling chain, preserving its call stack or associated data:
try...
Define your class that will represent your custom error.
public class ErrorDto
{
public int Code { get; set; }
public string Message { get; set; }
// other fields
public override string ToString()
{
return JsonConvert.SerializeObject(this);
}
}
Then put nex...
The idea is to use HttpContext.Response.OnStarting callback, as this is the last event that is fired before the headers are sent. Add the following to your middleware Invoke method.
public async Task Invoke(HttpContext context)
{
context.Response.OnStarting((state) =>
{
if ...
DELETE FROM `table_name` WHERE `field_one` = 'value_one'
This will delete all rows from the table where the contents of the field_one for that row match 'value_one'
The WHERE clause works in the same way as a select, so things like >, <, <> or LIKE can be used.
Notice: It is necessa...
DELETE FROM table_name ;
This will delete everything, all rows from the table. It is the most basic example of the syntax. It also shows that DELETE statements should really be used with extra care as they may empty a table, if the WHERE clause is omitted.
DELETE FROM `table_name` WHERE `field_one` = 'value_one' LIMIT 1
This works in the same way as the 'Delete with Where clause' example, but it will stop the deletion once the limited number of rows have been removed.
If you are limiting rows for deletion like this, be aware that it will delete th...
Getting current date is very easy. You get NSDate object of current date in just single line as follows:
Swift
var date = NSDate()
Swift 3
var date = Date()
Objective-C
NSDate *date = [NSDate date];