Tutorial by Examples: e

app/assets/javascripts/channels/notifications.coffee App.notifications = App.cable.subscriptions.create "NotificationsChannel", connected: -> # Called when the subscription is ready for use on the server $(document).on "change", "input", (e)=> ...
Java-like enumerations can be created by extending Enumeration. object WeekDays extends Enumeration { val Mon, Tue, Wed, Thu, Fri, Sat, Sun = Value } def isWeekend(day: WeekDays.Value): Boolean = day match { case WeekDays.Sat | WeekDays.Sun => true case _ => false } isWeekend...
An alternative to extending Enumeration is using sealed case objects: sealed trait WeekDay object WeekDay { case object Mon extends WeekDay case object Tue extends WeekDay case object Wed extends WeekDay case object Thu extends WeekDay case object Fri extends WeekDay case objec...
Creating a Snackbar can be done as follows: Snackbar.make(view, "Text to display", Snackbar.LENGTH_LONG).show(); The view is used to find a suitable parent to use to display the Snackbar. Typically this would be a CoordinatorLayout that you've defined in your XML, which enables adding ...
The String List passed as a parameter to the share() method contains the paths of all the files you want to share. It basically loops through the paths, adds them to Uri, and starts the Activity which can accept Files of this type. public static void share(AppCompatActivity context,List<Strin...
Functions can either be named or unnamed (anonymous functions): var namedSum = function sum (a, b) { // named return a + b; } var anonSum = function (a, b) { // anonymous return a + b; } namedSum(1, 3); anonSum(1, 3); 4 4 But their names are private to their own scope: ...
To avoid verbose null checking, the ?. operator has been introduced in the language. The old verbose syntax: If myObject IsNot Nothing AndAlso myObject.Value >= 10 Then Can be now replaced by the concise: If myObject?.Value >= 10 Then The ? operator is particularly powerful when you...
The NameOf operator resolves namespaces, types, variables and member names at compile time and replaces them with the string equivalent. One of the use cases: Sub MySub(variable As String) If variable Is Nothing Then Throw New ArgumentNullException("variable") End Sub The old sy...
This new feature makes the string concatenation more readable. This syntax will be compiled to its equivalent String.Format call. Without string interpolation: String.Format("Hello, {0}", name) With string interpolation: $"Hello, {name}" The two lines are equivalent and ...
Freddy is a JSON parsing library maintained by Big Nerd Ranch. It has three principal benefits: Type Safety: Helps you work with sending and receiving JSON in a way that prevents runtime crashes. Idiomatic: Takes advantage of Swift's generics, enumerations, and functional features, without...
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];
The number of seconds from the current date and time for the new date. Use a negative value to specify a date before the current date. For doing this we have a method named dateWithTimerIntervalSinceNow(seconds: NSTimeInterval) -> NSDate (Swift) or + (NSDate*)dateWithTimeIntervalSinceNow:(NSTime...
There are 4 methods for comparing dates: Swift isEqualToDate(anotherDate: NSDate) -> Bool earlierDate(anotherDate: NSDate) -> NSDate laterDate(anotherDate: NSDate) -> NSDate compare(anotherDate: NSDate) -> NSComparisonResult Objective-C - (BOOL)isEqualToDate:(NSDate *)anothe...
Get the description of an specific property in an object. var sampleObject = { hello: 'world' }; Object.getOwnPropertyDescriptor(sampleObject, 'hello'); // Object {value: "world", writable: true, enumerable: true, configurable: true}
Swift let alert = UIAlertController(title: "Hello", message: "Welcome to the world of iOS", preferredStyle: UIAlertControllerStyle.alert) let defaultAction = UIAlertAction(title: "OK", style: UIAlertActionS...
Compare method Either you implement a compare-method for your object: - (NSComparisonResult)compare:(Person *)otherObject { return [self.birthDate compare:otherObject.birthDate]; } NSArray *sortedArray = [drinkDetails sortedArrayUsingSelector:@selector(compare:)]; NSSortDescriptor NSS...
Custom Font Support Applications that want to use custom fonts can now include those fonts in their application bundle and register those fonts with the system by including the UIAppFonts key in their Info.plist file. The value of this key is an array of strings identifying the font files in the ...
We write custom action filters for various reasons. We may have a custom action filter for logging, or for saving data to database before any action execution. We could also have one for fetching data from the database and setting it as the global values of the application. To create a custom actio...
To get the timestamp in seconds Math.floor((new Date().getTime()) / 1000)
With UIAlertController, action sheets like the deprecated UIActionSheet are created with the same API as you use for AlertViews. Simple Action Sheet with two buttons Swift let alertController = UIAlertController(title: "Demo", message: "A demo with two buttons", preferredStyle...

Page 163 of 1191