Skip to content

Instantly share code, notes, and snippets.

View chrislonge's full-sized avatar

Chris Longe chrislonge

View GitHub Profile
@chrislonge
chrislonge / UIFontFamily.swift
Last active November 29, 2016 16:06
List all font families and font names in Swift 3
for family in UIFont.familyNames {
print(family)
for name in UIFont.fontNames(forFamilyName: family) {
print(name)
}
}
@chrislonge
chrislonge / SubviewLooper.m
Last active October 26, 2015 19:28
Loop through all subviews in a view and add border
for (UIWebView *webView in self.overdraftSection.subviews) {
webView.layer.borderColor = [[UIColor blackColor] CGColor];
webView.layer.borderWidth = 2.0f;
}
@chrislonge
chrislonge / post_install.rb
Last active July 18, 2016 13:46
post_install CocoaPod script to loop and print all targets and build configurations
post_install do |installer|
installer.pods_project.targets.each do |target|
puts "#{target}"
target.build_configurations.each do |config|
puts "#{config}"
end
end
end
@chrislonge
chrislonge / AttributedHTMLFont.swift
Created August 4, 2016 14:33
Attributed HTML With Custom Font Parsing (Playground)
import UIKit
import XCPlayground
XCPlaygroundPage.currentPage.needsIndefiniteExecution = true
let containerView = UIView(frame: CGRect(x: 0.0, y: 0.0, width: 375.0, height: 667.0))
containerView.backgroundColor = UIColor.whiteColor()
XCPlaygroundPage.currentPage.liveView = containerView
var aboutTextView = UITextView(frame: CGRect(x: 12.0, y: 20.0, width: containerView.frame.size.width - 12.0, height: 200.0))
aboutTextView.textAlignment = .Left

Swift Intro

Variables and Constants

Declare a variable with the var keyword.

var str = "Hello, playground" // str is of type string
str = 5 // This is an error, compiler won't let you assign an Int to a type String 

Swift is a type safe language, meaning once a variable is declared as a certain type, it must maintain that type.

If you don’t specify the type of value you need, Swift uses type inference.

@chrislonge
chrislonge / HashableTemplate.swift
Created July 21, 2019 22:34
Template to conform to Hashable
import Foundation
struct MyModel: Hashable {
let identifier = UUID()
func hash(into hasher: inout Hasher) {
hasher.combine(identifier)
}
static func == (lhs: MyModel, rhs: MyModel) -> Bool {
return lhs.identifier == rhs.identifier