Skip to content

Instantly share code, notes, and snippets.

View abbeyjackson's full-sized avatar
😬
Let's cross our fingers and hope Xcode builds!

Abbey Jackson abbeyjackson

😬
Let's cross our fingers and hope Xcode builds!
View GitHub Profile
//: Playground - noun: a place where people can play
import UIKit
import Foundation
// Merge overlapping times
// https://www.interviewcake.com/question/swift/merging-ranges?course=fc1&section=array-and-string-manipulation
/** Your company built an in-house calendar tool called HiCal. You want to add a feature to see the times in a day when everyone is available.
*/
@abbeyjackson
abbeyjackson / share test code
Created July 20, 2017 15:21
Encapsulate common testing code into one function but have the failures/successes show on the line that called the helper function. From Tim Vermeulenon iosdevelopers.io slack
func shared(value: Int, file: StaticString = #file, line: UIInt = #line) {
XCTAssert(value > 10, "value not greater than 10", file: file, line: line)
XCTAssert(value < 20, "value not less than 20", file: file, line: line)
}
func testFoo() {
shared(value: 15) // will pass
}
func testBar() {
@abbeyjackson
abbeyjackson / Translate touches to underneath view
Last active May 18, 2017 19:05
When you need to translate touches to views through other views you can use the hitTest method on the CONTAINING view. The hierarchy that this applies to is included as well.
class ContainerVC: BaseViewController {
override func loadView() {
view = ContainerView()
}
func addButton() {
// add the button
}
}
Creating a concurrent queue
let concurrentQueue = DispatchQueue(label: "queuename", attributes: .concurrent)
concurrentQueue.sync {
}
Create a serial queue
let serialQueue = DispatchQueue(label: "queuename")
serialQueue.sync {
@abbeyjackson
abbeyjackson / prepend UITextField
Last active July 21, 2016 21:18
Add $ or anything else to beginning of UITextField. The following will prepend a $ when the user types in a textfield and have it deleted when the user deletes their last character
func setUpPriceTextField() {
priceTextField.delegate = self
priceTextField.addTarget(self, action: #selector(textFieldDidChange), forControlEvents: .EditingChanged)
}
// MARK: UITextFieldDelegate
func textFieldDidBeginEditing(textField: UITextField) {
@abbeyjackson
abbeyjackson / iterate through an enum
Created May 5, 2016 19:32
iterate through an enum. Not possible but can fake it like this. If you conform to ForwardIndexType you can also use methods like advancedBy and distanceTo
enum Number: String, ForwardIndexType {
case One
case Two
case Three
case Four
case EndIndex
func successor() -> Number
{
switch self {
@abbeyjackson
abbeyjackson / view not tappable in KIF
Created May 2, 2016 23:30
view not tappable in KIF
let someView = tester().waitForViewWithAccessibilityLabel("Notify Customer")
guard let disabledButton = someView as? UIButton else {
XCTFail("This view should return a button")
return
}
XCTAssertFalse(disabledButton.enabled)
@abbeyjackson
abbeyjackson / new_gist_file_1
Created February 8, 2016 20:19
This is the source code for a centered scroll view xib file.
_
@abbeyjackson
abbeyjackson / remove file owner from xib
Created February 8, 2016 20:14
replace the file owner line with this
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
@abbeyjackson
abbeyjackson / NSRange from String
Created December 21, 2015 17:51
Return a NSRange from String instead of a Range<Index>
func nsRangeOfString(string: String) -> NSRange? {
guard let range = self.rangeOfString(string) else { return nil }
let startIndex = self.startIndex.distanceTo(range.startIndex)
return NSRange(location: startIndex, length: range.count)
}