Skip to content

Instantly share code, notes, and snippets.

View andyyhope's full-sized avatar

Andyy Hope andyyhope

View GitHub Profile
extension Selector {
static let coffeeMadeNotification = #selector(Customer.drink(_:))
}
class Customer {
@objc func drink(notification: NSNotification) {
print("Mmm... Coffee")
}
}
public class func drawConnectionError(frame frame: CGRect = CGRect(x: 0, y: -0, width: 66, height: 46)) {
//// Color Declarations
let fillColor = UIColor(red: 1.000, green: 1.000, blue: 1.000, alpha: 1.000)
let fillColor2 = UIColor(red: 0.000, green: 0.000, blue: 0.000, alpha: 0.204)
let fillColor3 = UIColor(red: 0.996, green: 0.792, blue: 0.180, alpha: 1.000)
//// Subframes
let group: CGRect = CGRect(x: frame.minX + floor(frame.width * 0.01153 - 0.26) + 0.76, y: frame.minY + floor(frame.height * 0.01752 + 0.25) + 0.25, width: floor(frame.width * 0.98712 + 0.35) - floor(frame.width * 0.01153 - 0.26) - 0.61, height: floor(frame.height * 0.99457 + 0.31) - floor(frame.height * 0.01752 + 0.25) - 0.06)
func instantiateViewController<T: UIViewController>() -> T where T: StoryboardIdentifiable {
guard let viewController = self.instantiateViewController(withIdentifier: T.storyboardIdentifier) as? T else {
fatalError("Couldn't instantiate view controller with identifier \(T.storyboardIdentifier) ")
}
return viewController
}
@andyyhope
andyyhope / SwiftEvolution_EnumCaseCountFunctionality_AndyyHope.md
Last active March 12, 2020 13:05
Swift Evolution - Enum Case Count Functionality

Swift Evolution Proposal

Author: Andyy Hope

Enum Values() Functionality (Update)

It has been brought to my attention that there was more use for the unintended values() functionality that I had outline in my "Other Languages" Java example below.

On the Swift Evolution mailing list, one developer outlined their requirement to loop through an array of enum case values to add different states to objects.

Another example where a values array would be useful if the developer wants to do something different for each different case, such as setting an image on a UIButton subclass for each different UIControlState

UIEdgeInsets separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
// Remove seperator inset
if ([self respondsToSelector:@selector(setSeparatorInset:)]) {
[self setSeparatorInset:separatorInset];
}
// Prevent the cell from inheriting the Table View's margin settings
if ([self respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
[self setPreservesSuperviewLayoutMargins:NO];
# tell ls to be colourful
export CLICOLOR=1
export LSCOLORS=gxBxhxDxfxhxhxhxhxcxcx
# tell grep to highlight matches
export GREP_OPTIONS='--color=auto'
# alias
source ~/.git-prompt.sh
source ~/.git-completion.bash
alias ls='ls -FGalh'
alias __git_ps1="git branch 2>/dev/null | grep '*' | sed 's/* \(.*\)/(\1)/'"