Posts

Showing posts from October, 2023

In my viewController for tableview cell want to focus the next textfield or textview while click on nex in keyboard iOS swift

 Problem: I'm having multiple number of cells with textfield and textview.While user click on next on keyboard then must be focused on next available textfield or textview.How do i achieve that? Solution:      func textFieldShouldReturn ( _ textField: UITextField) -> Bool {          IQKeyboardManager . shared . goNext () } Use the above method to achieve that.Alos you must have to set the delegate to the textfiled.

Issue scrollview content height iOS swift

 Problem: I'm having one scrollview with dynamic content.Inside the scrollview i'm having tableview inside the scroll view also tableview had dynamic content. I want tableview will not be scrollable and it will be update height based on its content.Also scrollview content size wants to be dynamic.How to achieve that? Solution: You ca easily achieve that.First in will display cell call the layoutsubviews for the dynamic cell fields.Inside willdisplay cell call the dynamic updated scrollview content height. Then it will works good..

Convert string to nsnumber,integer and trim the whitespaces in the string swift

 Solution: extension   String   {       var   trimStr : String ? {           return   self . trimmingCharacters ( in : . whitespacesAndNewlines )       }            func   nsNumber () ->   NSNumber   {           return   NSNumber ( value :   Int64 ( self )!)       }            func   toInt () ->   Int   {           return   Int ( self ) ?? 0       } }

Save custom object to userdefaults iOS swift

Problem:  I want to save my custom object into the userdefaults.I tried to save directly it throws exception Solution:   func getProfileData() -> MyModel {         if let value = self.userDefaults.object(forKey: "profilemodel") as? Data{             do {                 let decodedTeams = NSKeyedUnarchiver.unarchiveObject(with: value)                 let json = try JSONSerialization.data(withJSONObject: decodedTeams)                 let decoder = JSONDecoder()                 decoder.keyDecodingStrategy = .convertFromSnakeCase                 let decodedProfile = try decoder.decode(MyModel.self, from: json)                 return decodedProfile             } catch {                 print(error)             }         }         return MyProfileModel()     }          func setProfileData(value: MyModel) {         do {             let encodedResponse = (try? JSONSerialization.jsonObject(with: JSONEncoder().encode(value)))             let data = try NSKeyedArchiver.archivedData(

Eventstore permission error on iOS 17

 Problem: Event store permissions are to be like that below in previous versions of iOS but in iOS 17 it shows an exception.                     eventDB. requestFullAccessToEvents( completion: {(granted, error)  in                          if  granted { } }) Solution:          let  eventDB =  appdel . eventStoreNew ! // EKEventStore.init()          if   #available (iOS 17.0, *) {             eventDB. requestFullAccessToEvents( completion: {(grantedEvent, error)  in                  print (grantedEvent)             })             eventDB. requestFullAccessToReminders( completion: { (grantedEvent, error)  in                  if  grantedEvent { } }) else  {              // Fallback on earlier versions                          eventDB. requestAccess ( to : . event ,  completion : { (granted, error)  in                  if  granted {                 }})             eventDB. requestAccess ( to : . reminder ,  completion : { (grantedEvent, error)  in                  if  grantedEvent { } }) }

Collectionview height based on label text iOS swift

 Problem: I want to show the collection view cell height to be dynamic based on the label text.How can i achieve that? Solution:      func   collectionView ( _  collectionView:  UICollectionView ,  layout  collectionViewLayout:  UICollectionViewLayout ,  sizeForItemAt  indexPath:  IndexPath ) ->  CGSize  {          let  screenSize =  UIScreen . main . bounds          let  size = (screenSize. width ) /  CGFloat (1)          var  collheight = 30.0              if   let  item =  mystring  {                  let  labelHeight = item. content ?. height ( withConst rainedWidth : collectionView. bounds . size . wid th ,  font :  UIFont (). medium ())  // Adjust the font and other attributes as needed                 collheight = labelHeight! + 50             }          return   CGSize ( width : size,  height : collheight) }

How to show collectionview cells aligned horizontally iOS swift

Image
 Problem: I want collectionview cells to be aligned horizondally.Because default it had aligned vertically.How to solve that? Solution:      It had the above options like vertical and horizontal.You must have to select horizontal option in scroll direction.

libc++abi: terminating due to uncaught exception of type NSException iOS swift

Image
 Problem: 2023-10-04 12:23:24.365335+0530  app [13458:2205823] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<app.myCell 0x1062af440> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key someView.' *** First throw call stack: (0x1c7a80cb4 0x1c0b203d0 0x1c7bedc6c 0x1c1d9e76c 0x1c9dd6cf0 0x1c9dd6afc 0x1c7accba8 0x1c9d78b48 0x1c9b7bc90 0x1c9b7af58 0x102e5e738 0x102e657fc 0x1049e9374 0x1049e9468 0x10541f4dc 0x10541f5ac 0x1c9c2f2b4 0x1ca1df9b0 0x1ca1dfc88 0x1c9b0ef1c 0x1c9b0e7e0 0x1c9aea420 0x1c8fa4f30 0x1c9bb4b30 0x1c9bb49e8 0x1c9bb25b8 0x1ca9c73bc 0x1c9b16494 0x1c9e38908 0x1c9e2a7a8 0x1c9e2a680 0x1c9e2a554 0x1c9bb45e8 0x1c9bb331c 0x1c9bb2d44 0x1c9bb2b70 0x1c9b85b60 0x1c9f8bf34 0x1c9c31d40 0x1c9d9add4 0x1c9d9867c 0x1c9d977e8 0x1ca2e1b34 0x1c9ce69ac 0x1c9d97264 0x1c9cd7e70 0x1c9cd7d2c 0x1ca24a4d8 0x1c9c85ca8 0x1c9c85bdc 0x1c9c85af0 0x1c9b24428 0x1c9f2876c 0x1c7b07234 0x1c7a91410 0x1c7af119c 0x1c7af63ec

Collection view supplementary view not showing but i had implemented iOS swift

Problem:  I had registered supplementary view but it was not showing.Also it was not showing error rxswift. My code as like below.      func   setupRxBinding () {          //Collection bind                       collDataSource  = RxCollectionViewSectionedReloa dDataSource< SectionOfCollection >(                 configureCell: { (_, collectionView, indexPath, item)  in          // my cell configuration         })                       model . items . bind ( to :  mycollView . rx . items ( dataSource :  collDataSource )). disposed ( by :  disposeBag )                   mycollView . rx . itemSelected             . subscribe ( onNext : { [ weak   self ] indexPath  in                              }). disposed ( by :  disposeBag )          mycollView . rx . setDelegate ( self ). disposed ( by :  disposeBag )          collDataSource . configureSupplementaryView = { dataSource, collectionView, kind, indexPath  in              guard  kind ==  UICollectionView . elementKindSe ctionHeader  

I'm creating headerview for collectionview cells using rxswift.While run the code it crashes iOS swift

 Problem: I'm creating header view for collectionview cells using rxswift.While run the code it crashes.It show the below error. 2023-10-03 16:00:45.470422+0530 myapp[13244:2067307] *** Terminating app due to uncaught exception ' NSInternalInconsistencyExcepti on', reason: 'could not dequeue a view of kind: UICollectionElementKindSection Header with identifier HeaderCell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard' But i had registered the cell before using as like below.   self . mycollectionview . register ( HeaderCell . nib ,  forCellWithReuseIdentifier :  HeaderCell . identifier ) How to solve that? Solution: The problem was you are register the cell as  forCellWithReuseIdentifier but you have to register the cell as like below.Then only it will works.          mycollectionview . register ( Heade rCell . nib ,  forSupplementaryViewOfKind :  UICollectionView . elementKindSe ctionHeader ,  withReuseIdentifier : 

'dequeueReusableSupplementaryView' cannot be resolved without a contextual type iOS swift

 Problem: My code          collectionDataSource . configureSupplementaryView = { dataSource, collectionView, kind, indexPath  in              guard  kind ==  UICollectionView . elementKindSe ctionHeader   else  {                  fatalError ( "Unexpected supplementary view kind" )             }              let  headerView = collectionView. dequeueReusable SupplementaryView (                  ofKind : kind,                  withReuseIdentifier :  "HeaderCell" ,                  for : indexPath             )  as !  HeaderCell     // my configurations are here              return  headerView         } It shows error that 'dequeueReusableSupplementaryView' cannot be resolved without a contextual type. I don't know how to solve Solution: The above code is good only.You have to check the configuration that you had made in the code.Because if it had some errors it will show like that.So check the code lines.