This file contains 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
// | |
// Extensions.swift | |
// Apostle Partnerapp | |
// | |
// Created by Bas on 15/01/2015. | |
// Copyright (c) 2015 Bas. All rights reserved. | |
// | |
import UIKit |
This file contains 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
extension NSDate | |
{ | |
/** | |
Checks if the date is in the past. | |
:returns: If date is passed or not | |
*/ | |
func inPast() -> Bool | |
{ | |
let now = NSDate() |
This file contains 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
private static List<Map.Entry<String, Integer>> sortByValue(Map<String, Integer> unsortMap) | |
{ | |
List<Map.Entry<String, Integer>> list = new LinkedList<>(unsortMap.entrySet()); | |
// Sorting the list based on values | |
Collections.sort(list, new Comparator<Map.Entry<String, Integer>>() | |
{ | |
@Override | |
public int compare(Map.Entry<String, Integer> o1, | |
Map.Entry<String, Integer> o2) |
This file contains 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
/** | |
Filters the list of clients according to the query. | |
:param: searchText The query. | |
*/ | |
func filterContentForSearchText(searchText: String) | |
{ | |
self.filteredClients = self.clients.filter( | |
{ | |
(client: Client) -> Bool in |
This file contains 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
import Foundation | |
struct Message { | |
var timestamp: Double | |
} | |
extension Message: Printable { | |
var description: String { | |
return "Message with timestamp \(self.timestamp)" | |
} |
This file contains 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
import Foundation | |
enum Number: Int { | |
case Zero | |
case One | |
case Two | |
case Three | |
} | |
enum NumberString: String { |
This file contains 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
public protocol LowercaseInitializable { | |
static var allValues: [Self] { get } | |
init?(rawValue: String) | |
} | |
extension LowercaseInitializable { | |
public init?(rawValue: String) { |
This file contains 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
import Foundation | |
let jsonString = "{\"message\": \"422 Unprocessable Entity\",\"errors\": {\"email\": [\"The email has already been taken.\"],\"mobile_number\" : [\"The mobile number has already been taken.\"]}}" | |
let jsonData = jsonString.data(using: .utf8) | |
do { | |
if let jsonData = jsonData { | |
let object = try JSONSerialization.jsonObject(with: jsonData, options: []) as? [AnyHashable: Any] | |
} |
This file contains 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
import Foundation | |
URL(string: "https://en.wikipedia.org/wiki/Flesch–Kincaid_readability_tests#Flesch_reading_ease") // nil | |
URL(string: "https://en.wikipedia.org/wiki/Flesch-Kincaid_readability_tests#Flesch_reading_ease") // valid | |
URL(string: "https://en.wikipedia.org/wiki/Flesch–Kincaid_readability_tests#Flesch.E2.80.93Kincaid_grade_level") // nil | |
URL(string: "https://en.wikipedia.org/wiki/Flesch-Kincaid_readability_tests#Flesch.E2.80.93Kincaid_grade_level") // valid | |
"https://en.wikipedia.org/wiki/Flesch–Kincaid_readability_tests#Flesch_reading_ease" == | |
"https://en.wikipedia.org/wiki/Flesch-Kincaid_readability_tests#Flesch_reading_ease" // false |
This file contains 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 o1nil: Int? = nil | |
let o1: Int? = 1 | |
func switcher(_ a: Int?, _ b: Int?) { | |
switch (a, b) { | |
case (nil, nil): | |
print("nothing") | |
case (let thing?, nil): | |
print("lhs", thing) | |
case (nil, let thing?): |
OlderNewer