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
@abbeyjackson
abbeyjackson / HTML to NSAttributed String
Last active December 18, 2015 16:37
NSAttributed String from an HTML JSON response. Rather than putting it in a web view with dynamic height, can convert to an attributed string with formatting.
func getJSONData() -> NSData? {
guard let path = NSBundle.mainBundle().pathForResource("staticText", ofType: "json") else {
print("error finding file")
return nil
}
return NSData(contentsOfFile: path)
}
func dataToJSON(data:NSData) -> [String: AnyObject]? {
@abbeyjackson
abbeyjackson / Add feature branch name to commit - Global
Created November 24, 2015 17:03
Add feature branch name to git commit messages. Either do the global option or to add this to a repo, you can place the file in .git/hooks/prepare-commit-msg and make that file executable http://blog.bartoszmajsak.com/blog/2012/11/07/lazy-developers-toolbox-number-1-prepend-git-commit-messages/ https://coderwall.com/p/jp7d5q/create-a-global-git-…
git config --global init.templatedir '~/.git-templates'
mkdir -p ~/.git-templates/hooks
# Create ~/.git-templates/hooks/prepare-commit-msg with the above content
chmod +x ~/.git-templates/hooks/prepare-commit-msg
# In any existing git repos you want to have this hook
git init # this will copy the hooks into the git repo, but will not overwrite any existing hooks
let delay = 0.25 * Double(NSEC_PER_SEC)
let time = dispatch_time(DISPATCH_TIME_NOW, Int64(delay))
dispatch_after(time, dispatch_get_main_queue()) {
/// do stuff
}
@abbeyjackson
abbeyjackson / Protocol Delegate Pattern Explained
Created November 16, 2015 17:22
From ios-Developers Donny Wals.
Donny Wals [8:46 AM]
Imagine this, we’re going to build a house together. You are really good at the designing and overall building but plumbing isn’t your thing. So you want me to do the plumbing for you. You define a set of skills I need to have such as this list:
protocol NinjaPlumber {
func fixSink()
func layDownPipes()
func makeSureNothingIsClogged() -> Bool
func dance() // because we all need a dancing plumber
}
@abbeyjackson
abbeyjackson / compiler error macro
Created November 13, 2015 22:04
How to make methods unavailable, make compiler warnings / errors using #define statements
#define __SXMWebAction__UnavailableConstructor__(x) __attribute__((unavailable("This class must be instantiated using '"x"WithJSON:' or '"x"WithHTMLJSON:'")))
#pragma mark - Unavailable Super Methods
- (id)init __SXMWebAction__UnavailableConstructor__("init");
+ (id)new __SXMWebAction__UnavailableConstructor__("webAction");
@abbeyjackson
abbeyjackson / 1 unfuckxcode
Last active October 2, 2018 15:51
xcode alias, clears Xcode and sim caches from command line, "unfuckxcode-sim" will also reset the simulator contents.
alias unfuckxcode='rm -rf ~/Library/Developer/Xcode/DerivedData; rm -rf ~/Library/Caches/com.apple.dt.Xcode; rm -rf $(getconf DARWIN_USER_CACHE_DIR)/org.llvm.clang/ModuleCache; rm -rf /var/folders/**/com.apple.DeveloperTools*; rm -rf ~/Library/Developer/Xcode/DerivedData/ModuleCache; echo -e "\xF0\x9F\x94\xA5 BURN IT ALL\xF0\x9F\x94\xA5"'
@abbeyjackson
abbeyjackson / Dynamic Text
Created November 2, 2015 16:03
Supporting dynamic text and preferred font size
// configure labels:
- (void)configureView
{
self.textSizeLabel.text = [[UIApplication sharedApplication] preferredContentSizeCategory];
self.headlineLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline];
self.subheadLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline];
self.bodyLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
self.caption1Label.font = [UIFont preferredFontForTextStyle:UIFontTextStyleCaption1];
self.caption2Label.font = [UIFont preferredFontForTextStyle:UIFontTextStyleCaption2];
@abbeyjackson
abbeyjackson / Add xib or nib to VC
Last active November 24, 2015 17:39
instantiate a xib / nib in Swift via an extension and add to a VC
let footer = TaxEstimatorFooterView.newViewWithNib() as? TaxEstimatorFooterView
Objective-C:
for (NSString* family in [UIFont familyNames])
{
NSLog(@"%@", family);
for (NSString* name in [UIFont fontNamesForFamilyName: family])
{
NSLog(@" %@", name);
}
@abbeyjackson
abbeyjackson / custom Tab Bar with single IBAction
Created October 16, 2015 20:33
from @jazbo, custom tab bar using tags and no duplicate methods (one IBAction, one delegate method)
protocol SectionSelected {
func sectionSelected(section: SectionType)
}
class TestClass {
weak var tabBarDelegate: SectionSelected?
var sectionType: SectionType? {
didSet {
sectionSelected()