Posts

Showing posts from August, 2021

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 ) { }