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 url = URL(string: "https://rickandmortyapi.com/api/character/")! | |
| let config = URLSessionConfiguration.default | |
| if #available(iOS 11, *) { | |
| config.waitsForConnectivity = true | |
| } | |
| /* we keep a reference to the URLSession in case we need to invalidate */ | |
| session = URLSession(configuration: config, delegate: self, delegateQueue: OperationQueue.main) |
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
| /* | |
| * @description: query the given table based on conditions provided | |
| * @note statement example "SELECT * FROM table_name WHERE " | |
| * @param table SQL table name to insert values into | |
| * @param completion closure to be called when query is complete | |
| */ | |
| static func query(on table:String, where conditions:[WhereCondition]? = nil, completion:ResultCompletion){ | |
| var sqlStatement = "SELECT * FROM \(table)" | |
| var values = [Any]() |
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
| /* | |
| * @description: delete a row of data from a given table based on conditions | |
| * @note statement example "DELETE FROM table_name WHERE columnName = ? " | |
| * @param table SQL table name to insert values into | |
| * @param completion closure to be called when delete is complete | |
| */ | |
| static func delete(from table:String, where conditions:[WhereCondition], completion:Completion) { | |
| var sqlStatement = "DELETE FROM \(table)" | |
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
| /* | |
| * @description: Insert an array of values in the given table | |
| * @warning this assumes the first field is an autoincrementing value | |
| * @note statement example "INSERT INTO table_name VALUES (NULL, ?, ?, ?)" | |
| * @param values array of items to insert | |
| * @param table SQL table name to insert values into | |
| * @param completion closure to be called when insert is complete | |
| */ | |
| static func insert(values: [Any], into table:String, completion:Completion) { |
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
| class FMDBDatabase { | |
| /* | |
| * @description defines completion closure for database calls | |
| */ | |
| public typealias Completion = ((Bool, Error?)-> Void) | |
| public typealias ResultCompletion = ((Bool, FMResultSet?, Error?)-> Void) | |
| /* |
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
| /* | |
| * @description: creates a table with the specified list of columns and value types | |
| * @note statement example e.g."CREATE TABLE IF NOT EXISTS table_name (Title Text, Author Text, PublicationDate Date)" | |
| * @param table name of the table to create | |
| * @param columns list of TableColumn values to create the columns | |
| * @param completion closure to be called when create is complete | |
| */ | |
| static func create(table:String, columns:[TableColumn], completion:Completion) { | |
| var sqlStatement = "CREATE TABLE IF NOT EXISTS \(table) (ID Integer Primary key AutoIncrement," | |
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
| import UIKit.UIView | |
| class FireworksParticleView:UIView { | |
| var particleImage:UIImage? | |
| var flareImage:UIImage? | |
| override class var layerClass:AnyClass { | |
| return CAEmitterLayer.self | |
| } |
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
| import UIKit | |
| class SnowParticleView:UIView { | |
| var particleImage:UIImage? | |
| override class var layerClass:AnyClass { | |
| return CAEmitterLayer.self | |
| } | |
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
| @inlinable | |
| public func lexicographicallyPrecedes<OtherSequence: Sequence>( | |
| _ other: OtherSequence, | |
| by areInIncreasingOrder: (Element, Element) throws -> Bool | |
| ) rethrows -> Bool | |
| where OtherSequence.Element == Element { | |
| var iter1 = self.makeIterator() | |
| var iter2 = other.makeIterator() | |
| while true { | |
| if let e1 = iter1.next() { |
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
| @inlinable | |
| public __consuming func reversed() -> [Element] { | |
| // FIXME(performance): optimize to 1 pass? But Array(self) can be | |
| // optimized to a memcpy() sometimes. Those cases are usually collections, | |
| // though. | |
| var result = Array(self) | |
| let count = result.count | |
| for i in 0..<count/2 { | |
| result.swapAt(i, count - ((i + 1) as Int)) | |
| } |