This file contains 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" |
This file contains 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 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 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 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 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 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
enum TagColor { | |
case Red, Orange, Yellow, Green, Blue, Purple | |
func toUIColor() -> UIColor { | |
switch self { | |
case .Red: | |
return UIColor(red: 179, green: 47, blue: 60, alpha: 1) | |
case .Orange: | |
return UIColor(red: 248, green: 148, blue: 29, alpha: 1) | |
case .Yellow: |
This file contains 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 | |
class ViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate { | |
// Must be declared here! | |
var picker = UIImagePickerController() | |
// IBOutlets | |
This file contains 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
let formatter = NSNumberFormatter() | |
formatter.numberStyle = NSNumberFormatterStyle.CurrencyStyle | |
let costString = formatter.stringFromNumber(cost) |
This file contains 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
// Currency style | |
let formatter = NSNumberFormatter() | |
formatter.numberStyle = NSNumberFormatterStyle.CurrencyStyle | |
let costString = formatter.stringFromNumber(23.99) | |
// Round to nearest whole number | |
let wholeNumberformatter = NSNumberFormatter() | |
let wholeNumber = wholeNumberformatter.stringFromNumber(3.145) | |
// Round to nearest whole number |
OlderNewer