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
// Create a color | |
var myColor = TagColor.Red | |
// or, set a var to type TagColor | |
var aColor: TagColor | |
// Assign a TagColor | |
aColor = TagColor.Blue | |
// Alternately use the shorthand form | |
aColor = .Blue |
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 UIViewController { | |
func animateThing(thing: UIView, offsetX: CGFloat, offsetY: CGFloat, alpha: CGFloat, time: NSTimeInterval, delay: NSTimeInterval) { | |
let targetY = thing.center.y | |
let targetX = thing.center.x | |
let targetAlpha = thing.alpha | |
thing.center.y = thing.center.y - offsetY |
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 Array { | |
subscript (safe index: Int) -> Element? { | |
return indices ~= index ? self[index] : nil | |
} | |
} | |
// array[safe: index] |
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 stringToAttributedString() -> NSAttributedString { | |
var html = self | |
while let range = html.rangeOfString("\n") { | |
html.replaceRange(range, with: "</br>") | |
} | |
html = "<span style='font-family: Helvetica; font-size:14pt'>"+html+"</span>" | |
let data = html.dataUsingEncoding(NSUnicodeStringEncoding, allowLossyConversion: true) | |
let attrStr = try! NSAttributedString(data: data!, options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType], documentAttributes: nil) |
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 | |
import MessageUI | |
class ViewController: UIViewController, MFMailComposeViewControllerDelegate { | |
func sendEmail() { | |
let mailVC = MFMailComposeViewController() | |
mailVC.mailComposeDelegate = self | |
mailVC.setToRecipients([]) |
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 | |
import MessageUI // Import MessageUI | |
// Add the delegate protocol | |
class ViewController: UIViewController, MFMessageComposeViewControllerDelegate { | |
// Send a message | |
func sendMessage() { | |
let messageVC = MFMessageComposeViewController() | |
messageVC.body = "Message String" |
NewerOlder