Posts

Showing posts from 2021

UIAlertController inside alert shows error iOS swift

 Solution:   If you had multiple  UIAlertController then it will shows error.Then follow the below step. Add extra  UIKit that will be for additional alert.                          let  alertReplace =  UIAlertController ( title :  AppTitle ,  message :  messageToshow ,  preferredStyle : . alert )                          let  okReplaceAction = UIKit. UIAlertAction ( title :  "YES" ,  style : UIKit. UIAlertAction . Style . dest ructive ) {                             UIAlertAction  in // add the action here                         }                          let  cancelReplaceAction = UIKit. UIAlertAction ( title :  "NO" ,  style : UIKit. UIAlertAction . Style . canc el ) {                             UIAlertAction  in                                                      }                         alertReplace. addAction ( okReplaceAction)                         alertReplace. addAction ( cancelReplaceAction)                         view. present ( alertReplace,  anim

Tint color not set for asset images

Image
 Solution: You have to select the asset image and then change the settings as like above Render as -> Default to Render as -> Template image. After that you have to set the image tint color will works fine.

TableViewCell has "Class Cell has no initializers" error RXSwift

 Solution:      var   viewModel : My Model ? {          didSet  {              bindModel ()         }     } You must have to define the correct model in this.That's why the issue came.If model is wrong the above issue will shown...

Get the sender object from UITapGestureRecognizer

 Solution:                  let  tapGestureRecognizer =  UITapGestureRecognizer ( target : vc,  action :  #selector (vc. tapEventAction ( se nder :)))                 cell.i mg . addGestur eRecognizer ( tapGestureRecognizer)                 } When tap called       @objc   func   tapEventAction ( sender :  UITapGestureRecognizer ) {          let  btn = sender. view   as !  UIImageView }

{Error Domain=NSPOSIXErrorDomain Code=17 "File exists"}}]... iOS swift

 Problem: While i tried to copy one image from one path to another path.That time i faced the error like below. {Error Domain=NSPOSIXErrorDomain Code=17 "File exists"}}]... Solution: While copy the file you must have to append the filename in the pasted url path and paste it.Then only it will works good.Otherwise the above error will be occur.

SwipeCollectionViewCellDelegate not working iOS swift

 Problem: SwipeCollectionViewCellDelegate not working while using  swipecellkit. Solution: cell.delegate = self You must have the above line then only it will works

View not able to set constraints iOS swift

Image
Solution:  While setting constraints that not updated then must check the below condition.Layout must be infered not autoresizing.

KNContactsPicker remove empty phone numbers while picking contact swift

 Problem: I had used KNContactsPicker for adding contacts in my app.But it fetches empty phone numbers also .How to avoid fetching empty contacts swift? Solution: KNcontact picker had settings.You can also select multiple contacts.You can use the condition as below that  " !contact. phoneNumbers . isEmpty ".For fetching the contacts. Code: import  KNContactsPicker     var   settings  =  KNPickerSettings ()  settings . selectionMode  = . multiple settings . subtitleDisplayInfo  = . phoneNumber settings . conditionToDisplayCon tact  = { contact  in                  return  !contact. phoneNumbers . isEmpty             } let  controller =  KNContactsPicker ( delegate :  self ,  settings :  self . settings ) self . navigationController ?. pre sent (controller,  animated :  true ,  completion :  nil )

iOS Coding standards || XCode coding standards

 Solution: iOS had some specific guidelines for coding. Variable declaration: Variable must start with small letters.If they had second important name then that name have capital letter.Like below var name:String!  // correct var Name:String!  // wrong var firstName:String! //correct  var Firstname:String! //Wrong Function Declaration:    func didChangesFontSize (fontSize: Float ) // correct     func  D idchangesfontsize (fontSize: Float ) // Wrong  Functions must start with small letter and follow to capital letters.

'self' used before 'self.init' call or assignment to 'self' coredata

 Problem: Coredata error while initialize 'self' used before 'self.init' call or assignment to 'self' coredata Solution:    public   convenience   init ?(dictionary:  NSDictionary ) {      self . init () } Try like above

Terminating app due to uncaught exception 'NSRangeException', reason: '*** _oset_getObjectsRange: range {16, 16} extends beyond bounds [0 .. 29]' coredata delete

 Problem: While delete the coredata object the below error came. "Terminating app due to uncaught exception 'NSRangeException', reason: '*** _oset_getObjectsRange: range {16, 16} extends beyond bounds [0 .. 29]'"         for var j in 0..<myobject.orderset!.count {           let newmess = myobject.orderset![j] as! entity           deleteMessage(message: newmess!)         } Solution: Because you had tried to delete the object in one index but the array count is decremented that's the problem for exception.So you can reverse the indexes and delete the object.          for  index  in  ( 0 ..<  myobject.orderset !. count ). r eversed ()                {                  let   newmess  =  myobject.orderset ![index]           deleteMessage(message: newmess!)             }

Copy text from Mac to Simulator || copied to simulator ios

Image
 Solution: First you have to enable the pastboard option in the simulator. First open the simulator Goto Menu->Edit->Select Automatically sync Pasteboard The above screenshot explains to enable the paste option.You just copy the text from mac and paste it to the simulator using long press option. Happy coding..!

Slider based view rotation iOS swift

 Solution: The below function used for rotate one view and it will not affect the scaling in that view    func didRotate (rotateValue: Float ) {     let trans = my View . transform //backup scaling     let scaling = sqrt (trans. a * trans. a + trans. c * trans. c )     let transform = CGAffineTransform . init (scaleX: scaling, y: scaling)      my View . transform = transform //apply both scaling and rotation          my View . transform = aceView . draggableTextView . transform . rotated (by: CGFloat ( Double (exactly: rotateValue)! * Double . pi / 180 ))   }

Font functions as extension in iOS swift || Bold add,Bold remove,Italic add,Italic remove functions

 Solution: The below function used for add and remove the bold and italic to a particular text extension UIFont {   var isBold : Bool   {     return fontDescriptor . symbolicTraits . contains (. traitBold )   }      var isItalic : Bool   {     return fontDescriptor . symbolicTraits . contains (. traitItalic )   }      func setBold () -> UIFont   {     if isBold {       return self            } else {       var symTraits = fontDescriptor . symbolicTraits       symTraits. insert ([. traitBold ])       let fontDescriptorVar = fontDescriptor . withSymbolicTraits (symTraits)       return UIFont (descriptor: fontDescriptorVar!, size: 0 )     }   }      func setItalic ()-> UIFont   {     if isItalic {       return self     } else {       var symTraits = fontDescriptor . symbolicTraits       symTraits. insert ([. traitItalic ])       let fontDescriptorVar = fontDescriptor . withSymbolicTraits (symTraits)       return UIFont (descriptor: fontDescriptorVar!, size: 0 )

Save My app image to gallery iOS swift || Save Document directory image into Gallery iOS swift

Solution: In below function  MyImage is an image that i want to save it into my gallery.      UIImageWriteToSavedPhotosAlbum (MyImage, self , #selector ( image ( _ :didFinishSavingWithError:contextInfo:)), nil )    //MARK: - Add image to Library   @objc func image ( _ image: UIImage , didFinishSavingWithError error: Error ?, contextInfo: UnsafeRawPointer ) {        }

Check textView text is underlined in iOS swift

 Solution: The below function is used to check the textfiled,textView and label text has a property of underline.    func isUnderlined (attrText: NSAttributedString ) -> Bool {     var contains: ObjCBool = false     attrText. enumerateAttributes (in: NSRange (location: 0 , length: attrText. length ), options: []) { (dict, range, value) in       if dict. keys . contains (. underlineStyle ) {         contains = true       }     }     return contains. boolValue   } Usage                   if isUnderlined (attrText: my textField . attributedText ) { }

xcode error multiple commands produce core data

Image
 Solution: If you started with coredata and created models after that if run the app it shows an error like below. "xcode error multiple commands produce core data of your coredataClass"  Then you need to configure the coredata as like below image. Select your entity and click the last option in the right side menu as like above and click module default it selected class definition.You have to change it to manual/none. After that delete your coredata classes you created and create it again.It will solve your problem.

Alertbox function for common utils iOS swift || Alertbox custom function in common

 Solution: You can use the below function to show alert as a single function you can call wherever you want. Also must to be implement the extension of the application.      func showAlert(msg: NSString ,controller: UIViewController ) {         if let topController = UIApplication . topViewController () {             if ! (topController is UIAlertController ) {                 let alert = UIAlertController (title: "Apptitle"   as String , message: msg as String , preferredStyle: . alert )                 alert. addAction ( UIAlertAction (title: "OK" , style: . default , handler: nil ))                 topController. present (alert, animated: true , completion: nil )             }         }     } Use the extension of the application as like function below extension UIApplication {     class func topViewController(base: UIViewController ? = UIApplication . shared . keyWindow ?. rootViewController ) -> UIViewController ? {         if let nav = base as

iPhone simulator coredata data not clear while uninstall the app in Xcode

 Solution: It had two solutions. 1. You can go simulator menu Device -> erase all content and settings works well. 2. Also if you created group for your app and run it after that you can uninstall the app it will clear all data.

button title after image swift iOS || Align button title before button image iOS swift

 Solution: You can align the text in front of the button then you can set the image is possible like below:       cell. button . semanticC ontentAttribute  =  UIApplication . shared           . userInterfaceLayoutDirection  == . rightToLeft  ? . forceLeftToRight  : . forceRightToLeft

Take screenshot in iOS simulator

 Solution: You can easily take screenshots in the simulator.Just open the simulator and click command+S it will take screenshot in your simulator. Captured screenshot will be saved in the desktop on our Mac.

Get the bound box for a cgPath with +10 of width and height in swift iOS

 Solution:      let  selectionBox = appenedPath. boundingBox . insetB y (dx:  -10.0 , dy:  -10.0 )

Compare array contains same object iOS swift

 Solution: We had an option that will compare single array with its object's all are equal or different. In that we can use "Set" function like below. Code: let myArrayA = [1,2,3] let myArrayB = [1,1,1] If(Set(myArrayA).count == myArrayA.count) { print("different") } else { print("same") }  If(Set(myArrayB).count == myArrayB.count) { print("different") } else { print("same") }  The first one returns different and the second one returns same...Happy coding....

Copy Nsobject into new one iOS objective C

 Solution: You can use copywithzone function to create new entire nsobject and return it to your other class.You just call the NSObject.copy to get the entire copied object in iOS. If you did before creating this method it will be crashed.If you use the above method you will be easily handle the copy of our nsobject. Objective C: Declare the method in .h file and implement it in .m file to access it in anywhere.. -(id)copyWithZone:(NSZone *)zone { }

ACEDrawingVIew while clear after draw any objects black background object came || Blackbox around draw rect iOS swift

 Solution: In clear if you did aceView background color set to white then that issue will come. In clear you have to do clear the patharray,Undosteps,Redosteps and also clear the background color. You must have to set the backgroundcolor as clear color.After that issue will be resolved

Use zoom and touch gesture in a single View iOS swift

 Solution: You can use touch gesture as well as pan gesture in a single view.Scroll view used for zoom then you can just add one line that will say pan gesture for 2taps required. You can add pan gesture with two touches in scrollView with number of taps required = 2.Then if you touch with single finger it will act as touch.If you use two fingers then it will act as pan gesture...

#define array object in objective C iOS

 Solution: You can define only the values that contains single element.You cannot be able to define NSArray using define in Objective C. So better you can use the values in local variable.

How to check contains of object in one array in objective C iOS

 Solution: NSArray *arr = @[@1,@2,@3]; int value = 1; if([arr contains:value]) { NSlog("yes it's Available"); } else { NSlog("not Available"); }

Collection NSArrayM was mutated while being enumerated iOS swift

 Problem: While deleting an object from array produces error array was never muted while enumerated. Solution: You can easily get what the error is?. Because it says "array was muted while being enumerated".If you are using one array inside loop if you are deleting one object in the array it will be affect the loop count.So better you can use for each looping.In that count will not be used for enumeration.If ou delete objects it will not affect the loop...

Terminating app due to uncaught exception 'NSGenericException', reason: Collection NSArray was mutated while being enumerated mutablecopy

Problem: Mutable copy the coredata object and use as new object in iOS swift.   Solution: You cannot be able to mutablecopy the coredata object.So better using creating a new object and assign the values from the previous object.

set subview to its original position after bring subview to front iOS swift

 Solution:       I had some subviews of one view.I had set some views to bringsubview to front but i wanted those views to set back to its original order after the edit completed.      While adding subview to one View it had different tag for every subview.So its easy to set the order.ID based arrange order of it's subviews.

Could not load cocoapods module in iOS swift || cocoapod error while adding new pod

 Solution: I had added new pod in cocoapods but after implementation it shows build failed with error could not load the Cocoapod module. After add the cocopod inside podfile must have to quit the project and continue the installation process in terminal. After final success of pod implementation open the Xcode project of workspace then select the target of all pods and goto settings and select processor module as standard module from armv7. Clean the project and build it will works good...

Zoom of an UIView iOS swift || Zoom implementation but subview came with blur || pinch zoom implementation with subview's zoom iOS swift

 Solution: First you have to create one UIView embed in ScrollView.After that implement the scrollView delegate method like Below. MyView is the that i want to zoom.Assign the delegate of the scrollView to self. In ViewDidload must add the below code.      scrollView . delegate  =  self      scrollView . minimumZoomScale  =  1.0      scrollView . maximumZoomScale  =  10.0      scrollView . isScrollEnabled  =  true After that implement the below method func   viewForZooming (in scrollView:  UIScrollView ) ->  UIView ? {      if   isZoom  {        return   self . myView  }  else  {          return   nil       }   }         If you want to zoom the subviews of the view then implement the below delegate method. MyView1 is the subview of myView.You can implement to zoom more views for that.    func   scrollViewDidEndZooming ( _  scrollView:  UIScrollView , with view:  UIView ?, atScale scale:  CGFloat ) {      myView1 . contentScaleFactor  = scale   }