Skip to content

Instantly share code, notes, and snippets.

//Local Notification
let content = UNMutableNotificationContent()
content.title = "Introduction to Notifications"
content.subtitle = "Session 707"
content.body = "Woah! These new notifications look amazing! Don’t you agree?"
content.badge = 1
//Remote Notification
{
"aps" : {
UNUserNotificationCenter.current().getNotificationSettings { (settings) in // ... }
open class UNNotificationSettings : NSObject, NSCopying, NSSecureCoding {
open var authorizationStatus: UNAuthorizationStatus { get }
open var soundSetting: UNNotificationSetting { get }
open var badgeSetting: UNNotificationSetting { get }
open var alertSetting: UNNotificationSetting { get }
open var notificationCenterSetting: UNNotificationSetting { get }
open var lockScreenSetting: UNNotificationSetting { get }
open var carPlaySetting: UNNotificationSetting { get }
//Registration
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { (granted, error) in
// Enable or disable features based on authorization.
}
}
//UNAuthorizationOptions
public struct UNAuthorizationOptions : OptionSet {
public init(rawValue: UInt)
public static var badge: UNAuthorizationOptions { get }
var total = 0
for num in intArray {
total = total + num
}
let totalByReduce = intArray.reduce(0) { total, num in total + num }
let totalByReduceShortHand = intArray.reduce(0, combine: { $0 + $1 })
let shortReduce = intArray.reduce(0, combine: +)
let squaredMod = (1...10).map { $0 * $0 }.filter { $0 % 2 == 0 }
let mod = intArray.filter { $0 % 2 == 0 }
let mappedStrings = intArray.map { "\($0)" }
let squared = intArray.map { $0 * $0 }
let intArray = [0, 1, 2, 3, 4]
let mappedStrings = intArray.map { (number) -> String in
return "\(number)"
}
// ^ Result: ["0", "1", "2", "3", "4"]
let squared = intArray.map { (number) -> Int in
return number * number
@suraphanL
suraphanL / squaredInt.swift
Last active September 10, 2016 18:49
Squared Of Array of Int
let fibs = [0, 1, 2, 3, 4]
var squared: [Int] = []
for fib in fibs {
squared.append(fib * fib)
}
func convertArray(array: [Int]) -> [String]? {
// Nothing to do. Exiting.
guard array.count > 0 else { return nil}
// Things to convert.
var stringArray = [String]()
for int in array {
let string = "\(int)"