Tutorial by Examples: a

To search if a String contains a substring, do the following: NSString *myString = @"This is for checking substrings"; NSString *subString = @"checking"; BOOL doesContainSubstring = [myString containsString:subString]; // YES If targeting iOS 7 or OS X 10.9 (or earlier)...
Office Blog - Excel VBA Performance Coding Best Practices Often, best performance is achieved by avoiding the use of Range as much as possible. In this example we read in an entire Range object into an array, square each number in the array, and then return the array back to the Range. This accesse...
Variables hold data. Name them after what they're used for, not after their data type or scope, using a noun. If you feel compelled to number your variables (e.g. thing1, thing2, thing3), then consider using an appropriate data structure instead (e.g. an array, a Collection, or a Dictionary). Names...
Procedures do something. Name them after what they're doing, using a verb. If accurately naming a procedure is not possible, likely the procedure is doing too many things and needs to be broken down into smaller, more specialized procedures. Some common VBA naming conventions go thus: For all Pr...
Given the following HTML file: index.html <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>React Tutorial</title> <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.2.1/react.js"></script>...
<link rel="alternate stylesheet" href="path/to/style.css" title="yourTitle"> Some browsers allow alternate style sheets to apply if they are offered. By default they will not be applied, but usually they can be changed through the browser settings: Firefox l...
Unlike classes, structures cannot inherit: class MyView: NSView { } // works struct MyInt: Int { } // error: inheritance from non-protocol type 'Int' Structures, however, can adopt protocols: struct Vector: Hashable { ... } // works
If a case class has exactly two values, its extractor can be used in infix notation. case class Pair(a: String, b: String) val p: Pair = Pair("hello", "world") val x Pair y = p //x: String = hello //y: String = world Any extractor that returns a 2-tuple can work this way....
Similar to the while loop, only the control statement is evaluated after the loop. Therefore, the loop will always execute at least once. var i: Int = 0 repeat { print(i) i += 1 } while i < 3 // 0 // 1 // 2
You can use the Enumerable class alongside Linq queries to convert for loops into Linq one liners. Select Example Opposed to doing this: var asciiCharacters = new List<char>(); for (var x = 0; x < 256; x++) { asciiCharacters.Add((char)x); } You can do this: var asciiCharacter...
When you need to remove a specific value from an array, you can use the following one-liner to create a copy array without the given value: array.filter(function(val) { return val !== to_remove; }); Or if you want to change the array itself without creating a copy (for example if you write a fun...
From NSString: NSString *urlString = @"https://www.stackoverflow.com"; NSURL *myUrl = [NSURL URLWithString: urlString]; You can also use the following methods: - initWithString: + URLWithString:relativeToURL: - initWithString:relativeToURL: + fileURLWithPath:isDirectory: - initF...
The operator for an "exclusive or" (for short XOR) is: ^ This operator returns true when one, but only one, of the supplied bools are true. true ^ false // Returns true false ^ true // Returns true false ^ false // Returns false true ^ true // Returns false
It's possible to declare protocol name without methods: @protocol Person; use it your code (class definition, etc): @interface World : NSObject @property (strong, nonatomic) NSArray<id<some>> *employees; @end and later define protocol's method somewhere in your code: @protocol...
It is possible to bind values to names using @: struct Badger { pub age: u8 } fn main() { // Let's create a Badger instances let badger_john = Badger { age: 8 }; // Now try to find out what John's favourite activity is, based on his age match badger_john.age { ...
// Create a boolean value let a = true; // The following expression will try and find a pattern for our value starting with // the topmost pattern. // This is an exhaustive match expression because it checks for every possible value match a { true => println!("a is true"), ...
It's possible to treat multiple, distinct values the same way, using |: enum Colour { Red, Green, Blue, Cyan, Magenta, Yellow, Black } enum ColourModel { RGB, CMYK } // let's take an example colour let colour = Colour::Red; let model = match ...
Patterns can be matched based on values independent to the value being matched using if guards: // Let's imagine a simplistic web app with the following pages: enum Page { Login, Logout, About, Admin } // We are authenticated let is_authenticated = true; // But we aren't admins...
// View to hold the CAGradientLayer. let view: UIView = UIView(frame: CGRect(x: 0, y: 0, width: 320, height: 320)) // Initialize gradient layer. let gradientLayer: CAGradientLayer = CAGradientLayer() // Set frame of gradient layer. gradientLayer.frame = view.bounds // Color at...
By default the Python random module use the Mersenne Twister PRNG to generate random numbers, which, although suitable in domains like simulations, fails to meet security requirements in more demanding environments. In order to create a cryptographically secure pseudorandom number, one can use Syst...

Page 120 of 1099