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 dic = NSProcessInfo.processInfo().environment | |
| if dic["MY_VARIABLE"] != nil { | |
| // ... do secret stuff here ... | |
| } |
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 let urlpath = Bundle.main.path(forResource: "bpreg", ofType: "xml") { | |
| let url = NSURL.fileURL(withPath: urlpath) | |
| } | |
| let urlpath = Bundle.main.path(forResource: "sample", ofType: "mp3") | |
| let url = NSURL.fileURL(withPath: urlpath!) |
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 MyClass { | |
| static var instanceCount = 0 | |
| init() { | |
| super.init() | |
| MyClass.instanceCount += 1 | |
| if MyClass.instanceCount > 1 { | |
| print("MyClass.instanceCount : \(MyClass.instanceCount)") | |
| } | |
| } |
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 tapGesture = UITapGestureRecognizer.init(target: self, action: #selector(labelTapped(tapGesture:))) | |
| tapGesture.numberOfTapsRequired = 1 | |
| label?.isUserInteractionEnabled = true | |
| label?.addGestureRecognizer(tapGesture) | |
| // Notice: tapGesture is not reusable: create new one for each new element | |
| @objc func labelTapped(tapGesture:UITapGestureRecognizer){ | |
| } |
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 | |
| class UIPaddedLabel: UILabel { | |
| var padding = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0) | |
| public override func drawText(in rect: CGRect) { | |
| super.drawText(in: UIEdgeInsetsInsetRect(rect, padding)) | |
| } | |
| public override var intrinsicContentSize: CGSize { |
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 UILabel { | |
| func set(image: UIImage, size: CGSize) { | |
| let text = self.text ?? "" | |
| let attachment = NSTextAttachment() | |
| attachment.image = image | |
| let verticalPosition = (font.capHeight - size.height).rounded() / 2 | |
| attachment.bounds = CGRect(x: 0, y: verticalPosition, width: size.width, height: size.height) | |
| let attachmentStr = NSAttributedString(attachment: attachment) | |
| let mutableAttributedString = NSMutableAttributedString() |
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
| func setGradientBackground(view: UIView?) { | |
| guard let view = view else { | |
| return | |
| } | |
| let colorTop = .black | |
| let colorBottom = .white | |
| let gradientLayer = CAGradientLayer() | |
| gradientLayer.colors = [colorTop, colorBottom] |
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 let transformImage = myImageView.transform.rotated(by: .pi / 1) { | |
| myImageView.image = UIImage(named: "image_name") | |
| myImageView.transform = transformImage | |
| } |