Tutorial by Examples: c

Avoid code repetition in constructors by setting a tuple of variables with a one liner: class Contact: UIView { private var message: UILabel private var phone: UITextView required init?(coder aDecoder: NSCoder) { (message, phone) = self.dynamicType.setUp() su...
let mySwitch: UISwitch = { view.addSubview($0) $0.addTarget(self, action: "action", forControlEvents: .TouchUpInside) return $0 }(UISwitch())
Move every outlet to an NSObject. Then drag an Object from the library to the controller scene of the storyboard and hook the elements there. class ContactFormStyle: NSObject { @IBOutlet private weak var message: UILabel! { didSet { message.font = UIFont.systemFontOfSize(12) ...
//Swift let initialScreen = storyboard.instantiateInitialViewController() //Objective-c UIViewController *initailScreen = [storyboard instantiateInitialViewController];
//Swift let viewController = storyboard.instantiateViewControllerWithIdentifier("identifier") //Objective-c UIViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"identifier"];
Add a key named Required background modes in property list (.plist) file .. as following picture.. And add following code in AppDelegate.h #import <AVFoundation/AVFoundation.h> #import <AudioToolbox/AudioToolbox.h> AppDelegate.m in application didFinishLaunchingWithOptions [[...
public class MyDataExporterToExcell { public static void Main() { GetAndExportExcelFacade facade = new GetAndExportExcelFacade(); facade.Execute(); } } public class GetAndExportExcelFacade { // All services below do something by themselves, determine l...
Suppose you have two lists: A and B, and you need to find the elements that exist in both lists. You can do it by just invoking the method List.retainAll(). Example: public static void main(String[] args) { List<Integer> numbersA = new ArrayList<>(); List<Integer> numb...
The following is a simple example of using the strategy pattern without a context class. There are two implementation strategies which implement the interface and solve the same problem in different ways. Users of the EnglishTranslation class can call the translate method and choose which strategy t...
Assuming the call to your web application's login handler looks like this: https://somepage.com/ajax/login.ashx?username=admin&password=123 Now in login.ashx, you read these values: strUserName = getHttpsRequestParameterString("username"); strPassword = getHttpsRequestParameterSt...
Intent: Define an interface for creating an object, but let sub classes decide which class to instantiate. Factory Method lets a class defer instantiation to sub classes. UML diagram: Product: It defines an interface of the objects the Factory method creates. ConcreteProduct: Implements Produc...
Assume you have a application that administers rooms. Assume further that your application operates on a per client basis (tenant). You have several clients. So your database will contain one table for clients, and one for rooms. Now, every client has N rooms. This should mean that you have...
This example demonstrate how to add caching capabilities to DbProductRepository using Decorator pattern. This approach adheres to SOLID principles because it allows you to add caching without violating Single responsibility principle or Open/closed principle. public interface IProductRepository { ...
Input.acceleration is used to read the accelerometer sensor. It returns Vector3 as a result which contains x,y and z axis values in 3D space. void Update() { Vector3 acclerometerValue = rawAccelValue(); Debug.Log("X: " + acclerometerValue.x + " Y: " + acclerometerV...
You can use the DataExtension mechanism to add extra database fields to an existing DataObject: class MyMemberExtension extends DataExtension { private static $db = [ 'HairColour' => 'Varchar' ]; } And apply the extension: # File: mysite/_config/app.yml Member: exten...
You can add public methods to a DataObject using the extension mechanism, for example: class MyMemberExtension extends DataExtension { public function getHashId() { return sha1($this->owner->ID); } } When applied to the Member class, the example above would return...
BigInteger supports the binary logic operations that are available to Number types as well. As with all operations they are implemented by calling a method. Binary Or: BigInteger val1 = new BigInteger("10"); BigInteger val2 = new BigInteger("9"); val1.or(val2); Output:...
Simple case without duplicate keys Stream<String> characters = Stream.of("A", "B", "C"); Map<Integer, String> map = characters .collect(Collectors.toMap(element -> element.hashCode(), element -> element)); // map = {65=A, 66=B, 67=C} ...
'use strict'; const co = require('co'); module.exports = { // This is the index action and the route is mapped via /config/routes.js index(req, res) { co(function* index() { // Return a view without view model data // This typically will return the view defined at /vie...
Headers may be used to declare globally used read-only resources, like string tables for example. Declare those in a separate header which gets included by any file ("Translation Unit") which wants to make use of them. It's handy to use the same header to declare a related enumeration to ...

Page 288 of 826