Skip to content

Instantly share code, notes, and snippets.

View olivaresf's full-sized avatar

Fernando olivaresf

View GitHub Profile
class SettingViewControllerActionDecider : SettingViewControllerProtocol {
private let PasswordProtectedKey = "front"
var isPasswordProtected: Bool {
get {
guard let front = UserDefaults.standard.object(forKey: PasswordProtectedKey) as? Bool else { return false }
return front
}
import UIKit
protocol SettingViewControllerProtocol {
var isPasswordProtected: Bool { get set }
func validate(password: String?, confirmPassword: String?, from: SettingViewController) -> Bool
}
class SettingViewController: UIViewController {
class SettingViewController: UIViewController {
@IBOutlet weak var PasswordTextField: UITextField!
@IBOutlet weak var RepasswordTextField: UITextField!
@IBAction func Save(_ sender: UIButton) {
if PasswordTextField.text == RepasswordTextField.text {
self.userDefaults.set(PasswordTextField.text, forKey: "front")
self.userDefaults.synchronize()
private struct FetchSuccess {
let asignees: [IssueAssigneeViewModel]
let nextPage: Int?
}
private func fetch(owner: String,
repo: String,
pageNumber: Int,
completion: @escaping (Result<FetchSuccess>) -> Void) {
@olivaresf
olivaresf / 03082020-Githawk-1-solution.swift
Created August 2, 2020 02:03
First part of the solution.
override func fetch(page: String?) {
// Protect your inputs.
let requestedPage: Int
if let givenPageString = page,
let givenPageInt = Int(givenPageString) {
requestedPage = givenPageInt
} else {
requestedPage = 1
}
@olivaresf
olivaresf / 03082020-Githawk-1.swift
Created August 2, 2020 01:56
The original code
override func fetch(page: String?) {
client.client.send(
V3AssigneesRequest(
owner: owner,
repo: repo,
page: (page as NSString?)?.integerValue ?? 1
)
) { [weak self] result in
switch result {
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell",
for: indexPath as IndexPath) as! ContactCellTableViewCell
let contactsInSection = yourContacts[indexPath.section] as! NSArray
let contactForRow = contactsInSection[indexPath.row] as! APContact
cell.nameLabel.text = contactForRow.name?.compositeName ?? ""
cell.phoneLabel.text = contactForRow.phones?.first?.number
override func numberOfSections(in tableView: UITableView) -> Int {
guard yourContacts.count > 0 else { return 0 }
return UILocalizedIndexedCollation.current().sectionTitles.count
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
let contactsInSection = yourContacts.object(at: section) as! NSArray
return contactsInSection.count
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
// #warning Potentially incomplete method implementation.
// Return the number of sections.
var numberOfSections = UILocalizedIndexedCollation.currentCollation().sectionTitles.count
//println("numberOfSections: \(numberOfSections)")
return numberOfSections
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell:ContactCellTableViewCell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as ContactCellTableViewCell
if(yourContacts.count > 0){
let contact = yourContacts[indexPath.section][indexPath.row] as APContact
cell.nameLabel.text = contact.compositeName != nil ? contact.compositeName : ""
cell.phoneLabel.text = contact.phones.count > 0 ? contact.phones[0] as String : ""
cell.emailLabel.text = contact.emails.count > 0 ? contact.emails[0] as String : ""