Tutorial by Examples: ar

Sets are unordered collections of unique values. Unique values must be of the same type. var colors = Set<String>() You can declare a set with values by using the array literal syntax. var favoriteColors: Set<String> = ["Red", "Blue", "Green", "Blu...
A simple function that does not accept any parameters and does not return any values: func SayHello() { fmt.Println("Hello!") }
A function can optionally declare a set of parameters: func SayHelloToMe(firstName, lastName string, age int) { fmt.Printf("Hello, %s %s!\n", firstName, lastName) fmt.Printf("You are %d", age) } Notice that the type for firstName is omitted because it is identical ...
A basic struct is declared as follows: type User struct { FirstName, LastName string Email string Age int } Each value is called a field. Fields are usually written one per line, with the field's name preceeding its type. Consecutive fields of the sa...
The filter() method accepts a test function, and returns a new array containing only the elements of the original array that pass the test provided. // Suppose we want to get all odd number in an array: var numbers = [5, 32, 43, 4]; 5.1 var odd = numbers.filter(function(n) { return n % 2 !=...
In info.plist set View controller-based status bar appearance to YES In view controllers not contained by UINavigationController implement this method. In Objective-C: - (UIStatusBarStyle)preferredStatusBarStyle { return UIStatusBarStyleLightContent; } In Swift: override func pre...
A variadic function can be called with any number of trailing arguments. Those elements are stored in a slice. package main import "fmt" func variadic(strs ...string) { // strs is a slice of string for i, str := range strs { fmt.Printf("%d: %s\n", i, ...
In order to test the beginning and ending of a given string in Python, one can use the methods str.startswith() and str.endswith(). str.startswith(prefix[, start[, end]]) As it's name implies, str.startswith is used to test whether a given string starts with the given characters in prefix. >...
There are several PHP functions that accept user-defined callback functions as a parameter, such as: call_user_func(), usort() and array_map(). Depending on where the user-defined callback function was defined there are different ways to pass them: Procedural style: function square($number) { ...
// autoload.php spl_autoload_register(function ($class) { require_once "$class.php"; }); // Animal.php class Animal { public function eats($food) { echo "Yum, $food!"; } } // Ruminant.php class Ruminant extends Animal { public function eat...
An array in go is an ordered collection of same types elements. The basic notation to represent arrays is to use [] with the variable name. Creating a new array looks like var array = [size]Type, replacing size by a number (for example 42 to specify it will be a list of 42 elements), and replacing...
Perl tries to do what you mean: print "Hello World\n"; The two tricky bits are the semicolon at the end of the line and the \n, which adds a newline (line feed). If you have a relatively new version of perl, you can use say instead of print to have the carriage return added automatical...
> redirect the standard output (aka STDOUT) of the current command into a file or another descriptor. These examples write the output of the ls command into the file file.txt ls >file.txt > file.txt ls The target file is created if it doesn't exists, otherwise this file is truncated. ...
Browse to File > New > Solution to bring you up the new project dialog Select Single View App and press Next Configure your app by setting your app name and organization ID, and press Next: Set your Project name and Solution name, or leave as the default name. Click Create to create...
a = 1 - Math.abs(1 - a % 2); // This will throw an error if my arithmetic above is wrong. assert a >= 0 && a <= 1 : "Calculated value of " + a + " is outside of expected bounds"; return a;
Adapted from the tutorial, this uses the SwiftyDropbox library to download a file, with a progress callback on the download method to get progress information: // Download a file let destination : (NSURL, NSHTTPURLResponse) -> NSURL = { temporaryURL, response in let fileManager = NSFileMan...
This uses the Dropbox Python SDK to download a file from the Dropbox API at the remote path /Homework/math/Prime_Numbers.txt to the local file Prime_Numbers.txt: import dropbox dbx = dropbox.Dropbox("<ACCESS_TOKEN>") with open("Prime_Numbers.txt", "wb") as f:...
Dropbox.authorizedClient!.files.download(path: path, destination: destination).response { response, error in if let (metadata, url) = response { print("*** Download file ***") print("Downloaded file name: \(metadata.name)") print("Downloaded f...
This uses the SwiftyDropbox library to upload a file from a NSData to the Dropbox account, using upload sessions for larger files, handling every error case: import UIKit import SwiftyDropbox class ViewController: UIViewController { // replace this made up data with the real data le...
This example uses the Dropbox .NET library to upload a file to a Dropbox account, using upload sessions for larger files: private async Task Upload(string localPath, string remotePath) { const int ChunkSize = 4096 * 1024; using (var fileStream = File.Open(localPath, FileMode.Open)) ...

Page 9 of 218