Post

Replies

Boosts

Views

Activity

Property Wrapped Value if accessed from other files give non optional type
// MARK: UserDefault Property Wrapper @propertyWrapper struct UserPreferenceField<T : Codable> { let key: UserPreferenceFieldKey var wrappedValue : T? { get { guard let decodedData = UserDefaults.standard.value(forKey: key.rawValue) as? Data else { return nil } return try? JSONDecoder().decode(T.self, from: decodedData) } set { do { let encodedValue = try JSONEncoder().encode(newValue) UserDefaults.standard.set(encodedValue, forKey: key.rawValue) } catch { print("Error in saving codable value - \(error.localizedDescription)") } } } init(key:UserPreferenceFieldKey) { self.key = key } } enum UserPreferenceFieldKey : String { case userSelectedTags = "MLQUserSelectedTags" case userLastActivePlalist = "MLQUserLastActivePlalist" case userLastActivePlayableEntityMeta = "MLQUserLastActivePlayableEntityMeta" case currentUSer } struct HarkAppPreference { @UserPreferenceField(key: .userSelectedTags) static var userSelectedTags: [MLQTag] @UserPreferenceField(key: .userLastActivePlalist) static var userLastActivePlaylist: [PlayableEntity] @UserPreferenceField(key: .userLastActivePlayableEntityMeta) static var userLastActivePlayableEntityMeta: LastPlayableEntityMeta @UserPreferenceField(key: .currentUSer) static var user: User }This is my PropertyWrapper which I created to use for saving data to UserDefault, this worked to my expectations to use the value with optional chaining if used from within the file where I have written the PropertyWrapper code.But this given an error Initializer for conditional binding must have Optional type, not 'User' when used in another file like belowclass ABC { func sss(){ if let _ = HarkAppPreference.user { // here is gives errorwhen used in other file but work ok if used in same file } } }
2
0
1k
Dec ’19
UITableView header section height not called on scroll
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {               var data = ["abc djak da njdas sajlnakjs casjoas casklcnal csadjsa cnsljanl sd clnsdla ",                 "Sample cell with variable amount of text to demostrate the dynamic height of for the cell.",                 "Sample cell with variable amount of text to demostrate the dynamic height of for the cell. --- Sample cell with variable amount of text to demostrate the dynamic height of for the cell.",                 "Sample cell with variable amount of text to demostrate the dynamic height of for the cell. --- Sample cell with variable amount of text to demostrate the dynamic height of for the cell.--- Sample cell with variable amount of text to demostrate the dynamic height of for the cell. --- Sample cell with variable amount of text to demostrate the dynamic height of for the cell.", "Sample cell with variable amount of text to demostrate the dynamic height of for the cell.", "abc djak da njdas sajlnakjs casjoas casklcnal csadjsa cnsljanl sd clnsdla ",                 "Sample cell with variable amount of text to demostrate the dynamic height of for the cell.",                 "Sample cell with variable amount of text to demostrate the dynamic height of for the cell. --- Sample cell with variable amount of text to demostrate the dynamic height of for the cell.",                 "Sample cell with variable amount of text to demostrate the dynamic height of for the cell. --- Sample cell with variable amount of text to demostrate the dynamic height of for the cell.--- Sample cell with variable amount of text to demostrate the dynamic height of for the cell. --- Sample cell with variable amount of text to demostrate the dynamic height of for the cell.", "Sample cell with variable amount of text to demostrate the dynamic height of for the cell.",                 "abc djak da njdas sajlnakjs casjoas casklcnal csadjsa cnsljanl sd clnsdla ",                             "Sample cell with variable amount of text to demostrate the dynamic height of for the cell.",                             "Sample cell with variable amount of text to demostrate the dynamic height of for the cell. --- Sample cell with variable amount of text to demostrate the dynamic height of for the cell.",                             "Sample cell with variable amount of text to demostrate the dynamic height of for the cell. --- Sample cell with variable amount of text to demostrate the dynamic height of for the cell.--- Sample cell with variable amount of text to demostrate the dynamic height of for the cell. --- Sample cell with variable amount of text to demostrate the dynamic height of for the cell.", "Sample cell with variable amount of text to demostrate the dynamic height of for the cell."     ]     @IBOutlet weak var tableView: UITableView!          override func viewDidLoad() {         super.viewDidLoad()         // Do any additional setup after loading the view.                  // Register the custom header view.         let nib1 = UINib.init(nibName: "HSimpleSectionHeaderTypeTwoView", bundle: nil)            tableView.register(nib1, forHeaderFooterViewReuseIdentifier: "sectionHeader") //(HSimpleSectionHeaderTypeTwoView.self, forHeaderFooterViewReuseIdentifier: "sectionHeader")         let nib = UINib.init(nibName: "CustomTableViewCell", bundle: nil)         tableView.register(nib, forCellReuseIdentifier: "CustomTableViewCell")                  tableView.rowHeight = UITableView.automaticDimension         tableView.estimatedRowHeight = 100                  //tableView.sectionHeaderHeight = 50         //tableView.estimatedSectionHeaderHeight = 50     }     func numberOfSections(in tableView: UITableView) -> Int {         12     }          func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {         data.count     }          func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {         let cell = tableView.dequeueReusableCell(withIdentifier: "CustomTableViewCell") as! CustomTableViewCell                            cell.setCell(text: data[indexPath.row])          return cell     }          func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {         let view = tableView.dequeueReusableHeaderFooterView(withIdentifier:                        "sectionHeader") as! HSimpleSectionHeaderTypeTwoView            view.title = data[section]            return view     }     func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {         let feedHeaderView = tableView.dequeueReusableHeaderFooterView(withIdentifier: "sectionHeader") as! HSimpleSectionHeaderTypeTwoView         feedHeaderView.title = data[section]        return feedHeaderView.height     } } I am suppose to return dynamic height for header based on current text for section, but on scrolling table view i am not getting call in heightForSection method. But As per doumentation - https://developer.apple.com/documentation/uikit/views_and_controls/table_views/adding_headers_and_footers_to_table_sections It should call the heightForHeader delegate method.
0
0
836
Jan ’21
App Crash logs says its due to watch dog, How to find what is causing to crash the app
My App seeing crashes very rarely on some devices with this crash log, How to identify what is making iOS terminating the app due to extended time and watchdog issues is occurring. I tried to understand and locate the issue reading these articles but somewhat not getting exactly to pin it.  Read this but still not able to pin point Writing link to Question asked on Stackoverflow as here it was not accepting the length of the crash log. Question here
1
0
636
Oct ’21
AVPlayer fail to play audio with error "Cannot Complete Action -11819"
My App uses AVPlayer to play remote audio using remote url. Most of the time player is working fine but a few times around 5% of users see an issue of audio (remote url for media) not able to play and skips to next of error (internal app logic). But as soon this error "Cannot Complete Action -11819" is seen. It stays for some good time and App is not able to play any audio. The surprise part is after few tries it again start behaving normally (time is not certain).
1
0
901
Apr ’22