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
| var fruits = ["apple", "banana"] | |
| var names = ["ivan", "john", "maria"] | |
| var mainArray = [fruits, names] | |
| // i want to return true if theres a name/fruit that is "john" | |
| func search() -> Bool { | |
| for object in mainArray { | |
| if (object.filter { $0 == "john" }).count > 0 { | |
| return true | |
| } |
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
| if sender.text != "" { | |
| self.incidents = incidents.filter { $0.title.rangeOfString(sender.text, options: NSStringCompareOptions.CaseInsensitiveSearch) == "a" } | |
| } |
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
| class Cost { | |
| let cost: Double | |
| ... | |
| } | |
| func totalCost() { | |
| if let costs = [Costs...] { | |
| var cost = costs.reduce(0, combine: { (a, b) -> Double in | |
| return a.cost + b.cost |
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
| let date = NSDate() | |
| let formatter = NSDateFormatter() | |
| formatter.dateFormat = NSDateFormatter.dateFormatFromTemplate("YYYY-MM-d", options: 0, locale: NSLocale(localeIdentifier: "es_ES")) | |
| let second = formatter.dateFromString(formatter.stringFromDate(date)) | |
| println("First: \(formatter.stringFromDate(date))") | |
| println("Second: \(formatter.stringFromDate(second!))") | |
| "First: 25/05/2015" | |
| "Second: 21/12/2014" |
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
| var loadingView: Loading! //This is a UIView loaded from a Nib | |
| let delaySecs: NSTimeInterval = 2 | |
| UIView.animateWithDuration(delaySecs, animations: { () -> Void in | |
| self.loadingView.cherrysImageView.transform = CGAffineTransformMakeScale(2, 2) | |
| self.loadingView.cherrysImageView.alpha = 0 | |
| }) { (succeed) -> Void in | |
| //Can't remove the view here, otherwise i get NO animation | |
| //self.loadingView.removeFromSuperview() | |
| } | |
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
| @IBOutlet weak var cherrysImageView: UIImageView! | |
| let img = self.cherrysImageView.image?.imageWithRenderingMode(.AlwaysTemplate) | |
| self.cherrysImageView.image = img | |
| UIView.animateWithDuration(10, animations: { () -> Void in | |
| self.cherrysImageView.tintColor = UIColor.purpleColor() | |
| }) { (success) -> Void in | |
| } |
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
| class ImagePagerGermainView: ImagePagerView { | |
| override func awakeFromNib() { | |
| super.awakeFromNib() | |
| productImageView.clipsToBounds = true | |
| productImageView.layer.cornerRadius = productImageView.frame.size.width / 2 | |
| super.layoutSubviews() | |
| } | |
| } |
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
| @IBDesignable class CustomViewFromXib: UIView { | |
| var nibName: String = "CustomViewFromXib" | |
| override init(frame: CGRect) { | |
| super.init(frame: frame) | |
| setup() | |
| } | |
| required init(coder aDecoder: NSCoder) { |
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
| class GameScore { | |
| var score: Int = 0 | |
| static var sharedInstance = GameScore() | |
| class func getScore() -> Int? { | |
| return sharedInstance.score | |
| } | |
| } |
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
| class GameScore { | |
| func getScore() -> Int? { | |
| struct Holder { | |
| static var score: Int? | |
| } | |
| return Holder.score | |