This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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" : { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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 } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: +) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let squaredMod = (1...10).map { $0 * $0 }.filter { $0 % 2 == 0 } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let mod = intArray.filter { $0 % 2 == 0 } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let mappedStrings = intArray.map { "\($0)" } | |
let squared = intArray.map { $0 * $0 } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let fibs = [0, 1, 2, 3, 4] | |
var squared: [Int] = [] | |
for fib in fibs { | |
squared.append(fib * fib) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)" |