Skip to content

Instantly share code, notes, and snippets.

View amosavian's full-sized avatar

Amir Abbas Mousavian amosavian

View GitHub Profile
@amosavian
amosavian / imagepicker.swift
Created August 10, 2016 10:30
imagePicker delegate implementation
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
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
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 {
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)
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
domain=sabavision.com
domain=irpopup.ir
*/adv/*
##*#sabaIframe
##*.spbanners
##div.sidebar-tabliq
##div.text-tabliq
##div.cycle_adv_tabnak
##div.home_adv
|/advertisement.js*
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
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)
}
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
}
}
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)