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 sortedNumbers = [3, 1, 5, 6, 2, 4].sorted { $1 > $0 } | |
print(sortedNumbers) // [1, 2, 3, 4, 5, 6] |
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
func injected() { | |
self.view.backgroundColor = .green | |
} |
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
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { | |
// Override point for customization after application launch. | |
let vc = ViewController() | |
let window = UIWindow(frame: UIScreen.main.bounds) | |
window.rootViewController = vc | |
window.makeKeyAndVisible() | |
self.window = window | |
return true |
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
// http://nshipster.com/swift-objc-runtime/ | |
extension UIViewController { | |
private struct AssociatedKeys { | |
static var DescriptiveName = "nsh_DescriptiveName" | |
} | |
var descriptiveName: String? { | |
get { | |
return objc_getAssociatedObject(self, &AssociatedKeys.DescriptiveName) as? 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 SwipeTableViewCellDelegate: class { | |
func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath, for orientation: SwipeActionsOrientation) -> [SwipeAction]? | |
func tableView(_ tableView: UITableView, editActionsOptionsForRowAt indexPath: IndexPath, for orientation: SwipeActionsOrientation) -> SwipeTableOptions | |
} | |
/** | |
Default implementation of `SwipeTableViewCellDelegate` methods | |
*/ | |
public extension SwipeTableViewCellDelegate { | |
func tableView(_ tableView: UITableView, editActionsOptionsForRowAt indexPath: IndexPath, for orientation: SwipeActionsOrientation) -> SwipeTableOptions { |
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
// .filter() returns a new array of elements that satisfy a predicate declared in our closure | |
let evenNumbers = [1, 2, 3, 4, 5].filter { $0 % 2 == 0 } | |
// .map() returns a new array after applying a function to each element | |
let numbers = [1, 2, 3, 4, 5].map { $0 * 2 } | |
print(numbers) // [2, 4, 6, 8, 10] | |
// .flatMap() is like .map(), except it filters out any nil values | |
let arrayWithNoNils = [1, 2, 3, nil].flatMap { $0 } | |
print(arrayWithNoNils) // [1, 2, 3] |
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 UIKit | |
class ViewController: UIViewController { | |
let colors: [UIColor] = [.red, .blue, .green] | |
lazy var scrollView: UIScrollView = { | |
let scrollView = UIScrollView() | |
scrollView.delaysContentTouches = false | |
scrollView.isPagingEnabled = true |
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
class Person { | |
let name: String | |
var age: Int | |
init(name: String, age: Int) { | |
self.name = name | |
self.age = age | |
} | |
} |
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 UIKit | |
class MainController: Controller { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
controllerView = MainControllerView(controller: self) | |
} | |
override func setViewHandlers() { |
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 UIKit | |
import SnapKit | |
class MainControllerView: ControllerView { | |
// MARK: Views | |
let label: UILabel = { | |
let label = UILabel() | |
label.text = "Hello world" |