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 String { | |
| var isAllowedPhoneNumber: Bool { | |
| guard self.count > 0 else { return false } | |
| let nums: Set<Character> = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "+"] | |
| return Set(self).isSubset(of: nums) | |
| } | |
| } |
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 tap = UITapGestureRecognizer(target: self, action: #selector(self.openWebView(sender:))) | |
| cell.advtImage.isUserInteractionEnabled = true | |
| cell.advtImage.addGestureRecognizer(tap) | |
| func openWebView(sender: UITapGestureRecognizer) { | |
| let tapLocation = sender.location(in: self.collectionView) // Returns the CGPoints of the touched location | |
| if let indexPath = self.collectionView.indexPathForItem(at: tapLocation) // Returns the IndexPath at the above location { | |
| if let cell = self.collectionView.cellForItem(at: indexPath) as? Advertisment2 { | |
| if let url = URL(string: cell.url) { | |
| UIApplication.shared.openURL(url) |
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
| private func isNotificationGranted() -> Bool { | |
| if UIApplication.shared.currentUserNotificationSettings!.types == [] { | |
| return false | |
| } else { | |
| 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
| func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | |
| let cell = tableView.dequeueReusableCell(withIdentifier: "ProductOutletsTableViewCell", for: indexPath) as! ProductOutletsTableViewCell | |
| cell.showMoreButton.imageView?.transform = .identity | |
| return cell | |
| } | |
| func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { | |
| if indexPath.row == selectedRow { | |
| return 80 | |
| } |
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
| enum HttpMethods: String { | |
| case get = "get" | |
| case post = "post" | |
| case put = "put" | |
| case delete = "delete" | |
| case patch = "patch" | |
| } | |
| private func getJSON(data: Data) -> [String: Any]? { | |
| do { |
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 dateOutOf(Iso8601 date: String) -> Date { | |
| let dateFormatter = DateFormatter() | |
| // dateFormatter.calendar = Calendar(identifier: .iso8601) | |
| // dateFormatter.locale = Locale(identifier: "en_US_POSIX") | |
| dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSz" //Your date format | |
| dateFormatter.timeZone = TimeZone(secondsFromGMT: 0) //Current time zone | |
| let date = dateFormatter.date(from: date) //according to date format your date string | |
| return date! //Convert String to Date | |
| } |
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
| /* | |
| When we give dynamic height for the UITableViewCell, sometimes the below line gets truncated, by doing this it can be prevented. | |
| */ | |
| func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | |
| let cell = tableView.dequeueReusableCell(withIdentifier: "NotifyTableViewCell") as! NotifyTableViewCell | |
| cell.bounds = CGRect(x: 0, y: 0, width: tableView.bounds.width * 0.9, height: 99999) | |
| cell.contentView.bounds = cell.bounds | |
| cell.layoutIfNeeded() | |
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 insertDatePicker() { | |
| let inputView = UIView(frame: CGRect(x: 0,y: 0, width: self.view.frame.width, height: 240)) | |
| let datePicker = UIDatePicker(frame: CGRect(x: 0, y: 0, width: self.view.bounds.width, height: 240)) | |
| datePicker.datePickerMode = .date | |
| let now: Date = Date() | |
| var plusOneDay: DateComponents = DateComponents() | |
| plusOneDay.day = +1 | |
| let oneDayAfter: Date = (Calendar.current as NSCalendar).date(byAdding: plusOneDay, to: now, options: NSCalendar.Options.init(rawValue: 0))! | |
| datePicker.minimumDate = oneDayAfter |
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 CustomeView: UIView { | |
| // This view is the xib's view. | |
| @IBOutlet var view: UIView! | |
| // MARK: - Initializers | |
| override init(frame: CGRect) { | |
| super.init(frame: frame) | |
| setupView() | |
| } |
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 CoreGraphics | |
| extension CGFloat { | |
| func toRadians() -> CGFloat { | |
| return self * CGFloat.pi / 180 | |
| } | |
| func toDegress() -> CGFloat { | |
| return self * 180 / CGFloat.pi |