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
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) { | |
if let pickedURL = info[UIImagePickerControllerReferenceURL] as? NSURL { | |
let result = PHAsset.fetchAssetsWithALAssetURLs([pickedURL], options: nil) | |
if let asset = result.lastObject as? PHAsset { | |
let options = PHImageRequestOptions() | |
options.networkAccessAllowed = true | |
options.progressHandler = { (progress, _, _, _) in | |
self.setProgress(Float(progress), withTitle: "Fetching Image...") | |
} | |
PHImageManager.defaultManager().requestImageDataForAsset(asset, options: options, resultHandler: { (photoData, photoUTI, photoOrientation, photoInfo) -> Void in |
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
func removeScheduleTask() { | |
guard let scheduleId = dlItem?.scheduledIdentifier, let appId = OneSignal.app_id() else { | |
return | |
} | |
NSURLSession.sharedSession().dataTaskWithURL(NSURL(string: "https://onesignal.com/api/v1/notifications/\(scheduleId)?app_id=\(appId)")!) { (data, response, error) in | |
if let error = error { | |
Utility.UI.alertShow(NSLocalizedString("An error has been occured in server: \(error.localizedDescription)", comment: "schedule download task error"), withTitle: NSLocalizedString("Schedule", comment: "schedule download task error"), viewController: self) | |
} | |
if let r = response as? NSHTTPURLResponse where r.statusCode == 200 { | |
self.dlItem?.scheduledIdentifier = 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
static func showCommentOnView(view: UIView, comment: String = "", topPadding: CGFloat = 0) { | |
if let view = view as? UITableView { | |
view.backgroundView = nil | |
} else if let view = view as? UICollectionView { | |
view.backgroundView = nil | |
} | |
while let commentView = view.viewWithTag(1001) { | |
commentView.removeFromSuperview(); | |
} | |
if !comment.isEmpty { |
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
func correctFuckingResumeData(data: NSData?) -> NSData? { | |
let kResumeCurrentRequest = "NSURLSessionResumeCurrentRequest" | |
let kResumeOriginalRequest = "NSURLSessionResumeOriginalRequest" | |
guard let data = data, let resumeDictionary = (try? NSPropertyListSerialization.propertyListWithData(data, options: [.MutableContainersAndLeaves], format: nil)) as? NSMutableDictionary else { | |
return nil | |
} | |
resumeDictionary[kResumeCurrentRequest] = correctFuckingRequestData(resumeDictionary[kResumeCurrentRequest] as? NSData) |
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
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) { | |
if let pickedURL = info[UIImagePickerControllerReferenceURL] as? URL { | |
let result = PHAsset.fetchAssets(withALAssetURLs: [pickedURL], options: nil) | |
if let asset = result.lastObject { | |
let options = PHImageRequestOptions() | |
options.isNetworkAccessAllowed = true | |
options.progressHandler = { (progress, _, _, _) in | |
self.setProgress(Float(progress), withTitle: "Fetching Image...") | |
} | |
PHImageManager.default().requestImageData(for: asset, options: options, resultHandler: { (photoData, photoUTI, photoOrientation, photoInfo) -> Void in |
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
domain=sabavision.com | |
domain=irpopup.ir | |
*/adv/* | |
##*#sabaIframe | |
##*.spbanners | |
##div.sidebar-tabliq | |
##div.text-tabliq | |
##div.cycle_adv_tabnak | |
##div.home_adv | |
|/advertisement.js* |
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 UIImageView { | |
/// Loads image from web asynchronosly and caches it, in case you have to load url | |
/// again, it will be loaded from cache if available | |
func load(url: URL, placeholder: UIImage?, cache: URLCache? = nil) { | |
let cache = cache ?? URLCache.shared | |
let request = URLRequest(url: url) | |
if let data = cache.cachedResponse(for: request)?.data, let image = UIImage(data: data) { | |
self.image = image | |
} else { | |
self.image = placeholder |
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
override func viewWillAppear(_ animated: Bool) { | |
// Note cell keybaord adjustment | |
NotificationCenter.default.addObserver(self, selector: #selector(adjustViewForKeyboardNotification(_:)), name: Notification.Name.UIKeyboardWillShow, object: nil) | |
NotificationCenter.default.addObserver(self, selector: #selector(adjustViewForKeyboardNotification(_:)), name: Notification.Name.UIKeyboardWillHide, object: nil) | |
} | |
override func viewWillDisappear(_ animated: Bool) { | |
NotificationCenter.default.removeObserver(self) | |
} |
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 NSDictionary { | |
convenience init ? (json: String) { | |
if let data = (try? JSONSerialization.jsonObject(with: json.data(using: String.Encoding.utf8, allowLossyConversion: true)!, options: .mutableContainers)) as? NSDictionary { | |
self.init(dictionary: data) | |
} else { | |
self.init() | |
return 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 String { | |
func height(_ width: CGFloat, font: UIFont, lineBreakMode: NSLineBreakMode?) -> CGFloat { | |
var attrib: [String: AnyObject] = [NSFontAttributeName: font] | |
if lineBreakMode != nil { | |
let paragraphStyle = NSMutableParagraphStyle(); | |
paragraphStyle.lineBreakMode = lineBreakMode!; | |
attrib.updateValue(paragraphStyle, forKey: NSParagraphStyleAttributeName); | |
} | |
let size = CGSize(width: width, height: CGFloat(DBL_MAX)); | |
return ceil((self as NSString).boundingRect(with: size, options: NSStringDrawingOptions.usesLineFragmentOrigin, attributes:attrib, context: nil).height) |
OlderNewer