(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
// displaying only relevant content not all the functions | |
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { | |
// other stuff of didFinishLaunchingWithOptions inside app delegate | |
if #available(iOS 10.0, *) { | |
UNUserNotificationCenter.current().delegate = self | |
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound] | |
UNUserNotificationCenter.current().requestAuthorization( |
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) { | |
print("Dhruw: Dumping notification payload") | |
if application.applicationState != .active { | |
let value1: String? = userInfo["key1"] as? String | |
let value2: String? = userInfo["key2"] as? String | |
let value3: Bool? = userInfo["key3"] as? Bool | |
// do something with the received data | |
} | |
} |
// HTTP URL : https://fcm.googleapis.com/fcm/send | |
{ | |
"registration_ids":["XXXXXXXXXXXX:APA91XXXX7ziO-XXXXXXXXXXXXXXXXXXXXXX3B7OzLmNoAfHmZ3ju1M8gk7d-fYwXXXXXXdOHiwNhP6ThXNizSAu-Q0RkywWR8YCEiXf6a4Y803HY1t-XXXXXXXXXXX"], | |
"notification": { | |
"title":"Venue change for Avengers secret meet", | |
"body":"Tap here to open location on your phone" | |
}, | |
"data": { | |
"latitude" : "39.204720", | |
"longitude" : "-96.564909", |
curl -i -H 'Content-type: application/json' -H 'Authorization: key=<your_server_key>' -XPOST https://fcm.googleapis.com/fcm/send -d '{ | |
"registration_ids":["registration_ids", "of the", "target", "devices as array"], | |
"notification": { | |
"title":"Title of your notification", | |
"body":"content of your notification" | |
}, | |
"data": { | |
"key1" : "value1", | |
"key2" : "value2", | |
"key3" : 23.56565, |
(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
.monaco-shell { | |
font-family: "Operator Mono", "Inconsolata", monospace; | |
} | |
/* This makes the dirty tab circle yellow */ | |
.vs-dark | |
.monaco-workbench | |
> .part.editor | |
> .content | |
> .one-editor-silo |
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>DVTConsoleDebuggerInputTextColor</key> | |
<string>0 0 0 1</string> | |
<key>DVTConsoleDebuggerInputTextFont</key> | |
<string>SFMono-Bold - 11.0</string> | |
<key>DVTConsoleDebuggerOutputTextColor</key> | |
<string>0 0 0 1</string> |
Bank bank = .... ; | |
List<Customer> customers = bank.getCustomers(); // Get all bank customers | |
List<Transaction> = customer.getTransactions(); // Get all transactions by 1 customer | |
double amount = transaction.getAmount(); // Get transaction amount | |
String transactionType = transaction.getType(); // Get type of transaction (deposit or withdraw) |
// JAVA WAY - Who has minimum balance | |
Customer minBalanceCustomer = Collections.min( | |
customers, (o1, o2) -> (int) (o1.getBalance() - o2.getBalance()) | |
); |
// THE KOTLIN WAY | |
// 1. Who did maximum number of transactions | |
val maxTransactionsBy = customers.maxBy { it.transactions.count() } | |
// List all transactions irrespective of customers | |
val transactions = customers.flatMap { it.transactions } | |
// 2a. Get total amount deposited in the bank (use transactions constant from above) | |
val totalAmountDeposited = transactions.filter { it.type == "deposit" }.sumByDouble { it.amount } |