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
@objc var closureInitialization : UIButton = { | |
// Cannot use self in closure initialization | |
let btn = UIButton() | |
return btn | |
}() | |
// Lazy property closure init | |
let textColor : UIColor | |
@objc lazy var errorMsgLabel : UILabel = { |
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
1. Set and hit a breakpoint in the app, and write the following in the Xcode Console (next to the Variables View): | |
2. po NSHomeDirectory() | |
3. open terminal and change directory | |
4. run command in terminal | |
open . |
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
/* | |
Using Swift code inside an Objective-C file | |
*/ | |
// In a project : | |
// Use product module name found in build settings | |
#import "ProductModuleName-Swift.h" | |
// Within a Framework | |
#import <FrameworkName/FrameworkName-Swift.h> |
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
func testNextVC() { | |
// Can query elements by accessibility identifier or accessibility label | |
// Use Accessibility Identifier instead of accessibility label for ui tests! | |
let button = app.buttons["btnAccessibiityLabel"] | |
XCTAssertTrue(button.exists) | |
button.tap() | |
// Find ui element by accessibility identifer | |
let vcLabel = app.staticTexts["labelAccessibilityIdentifier"] |
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
// In a view subclass's layoutSubviews() | |
let roundPAth = UIBezierPath(roundedRect: bounds, cornerRadius: bounds.height / 2) | |
let maskLayer = CAShapeLayer() | |
maskLayer.path = roundPath.cgPath | |
layer.mask = maskLayer |
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
extension UIStackView { | |
convenience init(labelTitles: [String]) { | |
self.init() | |
for title in labelTitles { | |
let label = UILabel() | |
label.text = title | |
addArrangedSubview(label) | |
} |
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 | |
extension UIScrollView{ | |
func currentPage() -> Int{ | |
let page = Int((self.contentOffset.x / self.frame.size.width).rounded()) | |
print("page num : \(page)") | |
return page | |
} | |
} |
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
extension String{ | |
func charAtIndex(index : Int) -> Character{ | |
let i = self.index (self.startIndex, offsetBy: index) | |
return self[i] | |
} | |
func stringAtIndex(index : Int) -> String{ | |
let i = self.index (self.startIndex, offsetBy: index) | |
return String(self[i]) | |
} |
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
struct GenericQueue<Element>{ | |
fileprivate var elements : [Element] = [] | |
mutating func enqueue(newElement : Element){ | |
elements.append(newElement) | |
} | |
mutating func dequeue(){ | |
guard !elements.isEmpty else { | |
print("queue is empty") |
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
struct GenericStack<Element>{ | |
fileprivate var elements : [Element] = [] | |
mutating func pop(){ | |
guard !elements.isEmpty else{ | |
return | |
} | |
elements.removeLast(1) | |
} | |