Posts

Copy and paste the coredata object in my project iOS swift

 Problem: I want to copy my coredata object into cache and paste it somewhere in my project.How can i achieve that? Solution: You have to achieve that by using userdefaults in your project.But you cannot save the entire object in the defaults.So you have to store the coredata object ID in the defaults. While paste fetch the object based on coredata id and then paste it somewhere.      //  MARK: -  copy and paste the object      func   setCopyMyObj ( value :  myObject ) {          self . userDefaults . set (value. ob jectID . uriRepresentation (). abs oluteString ,  forKey :  " myobj " )              self . saveValue ()     }           func   removeCopyObj () {        self . userDefaults . removeObject ( forKey :  " myobj " )        self . saveValue ()     }           func   getCopyObj( )->  myObject ? {          guard   let  objID =  UserDefaults . standard . string ( f orKey :  "myobj" )  else  {              return   nil         }          let  contex

Increase font size of my editor XCode iOS

Problem:  I want to change my xcode editor font size to be increase or decrease. How can i changes that? Solution: command key and + key to be pressed on same time to increase the font size of xcode editor. command key and - key to be pressed on same time to decrease the font size of xcode editor.

Type 'mymodel' does not conform to protocol 'Decodable' iOS swift

Problem:  Type 'mymodel' does not conform to protocol 'Decodable'.Error came for my code. struct   mymodel : Decodable  {      var   startsOn : Int64  = 0      var   endsOn : NSNumber  = 0      var   objID : String  =  "" } Solution: Because it has nsnumber object inside.It will not be decodable.You have to change like below.It will works fine. struct   mymodel : Decodable  {      var   startsOn : Int64  = 0      var   endsOn :  Int64  = 0      var   objID : String  =  "" }

String had html elements want to display with trim some substring in iOS swift

 Problem: I'm having my webview with some html content and i had the html string.I want to trim the string with my limit and also change the attributes of the string to some new attributes.How can i achieve that? Solution: extension   NSMutableAttributedString   {       func   prefix ( _   maxLength:   Int ) ->   NSMutableAttributedString   {           guard   maxLength > 0   else   {   return   NSMutableAttributedString () }           guard   maxLength <   self . length   else   {   return   self   }           let   prefixRange =   NSRange ( location : 0,   length :   min (maxLength,   self . length ))           let   prefixAttributedString =   self . attributedSubstring ( from : prefixRange)           return   NSMutableAttributedString ( attr ibutedString : prefixAttributedString)       } }       var   attrmyString :   NSAttributedString   {                    let   attr =     NSMutableAttributedString ( attr ibutedString :   self . htmlAttributedString () ??   NSAttribu

Copy image option from other apps to my app iOS swift.

 Problem: I want to copy one image from other apps like whatsapp, chrome and others in my iphone and paste inside my app.How can i achieve that? Solution:          if   let   pastedImage =   UIPasteboard . general . image   {                            let   pasteActionButton =   UIAlertAction ( title : "paste" ,   style : . default ) { action ->   Void   in                    // paste action here             }               alert. addAction ( pasteActionButton)           } The above code will check that pasting content is image and then proceed that to show paste option in alert. Inside paste action you can you can use pastedImage to get the copied image from other apps.

tel not open call ios webview swift

 Problem: I want to open telephone call option ahile add numbers as link in webview.How can i achieve that? Solution: public   func   webView ( _  webView:  WKWebView ,  decidePolicyFor  navigationAction:  WKNavigationAction ,  decisionHandler :  @escaping  ( WKNavigationActionPolicy ) ->  Void ) {          if  navigationAction. request . url ?. scheme  ==  "tel"  {              UIApplication . shared . open ( navigationAction. request . url !)              return  decisionHandler(. cancel )         }  else  {              return  decisionHandler( WKNavigationAc tionPolicy . allow );         } } Use the above code to achieve that.While tap on the link it will show you telephone call option.

'setMenuVisible(_:animated:)' was deprecated in iOS 13.0: Use showMenuFromView:rect: or hideMenuFromView: instead iOS swift

 Problem: My code for my dropdown menu as like below.         menu.setTargetRect(CGRect(x: cell.frame.midX, y: cell.frame.origin.y+25, width: 20, height: 20), in: cell.superview!)         menu.setMenuVisible(true, animated: true) The above code shows warning as like below. 'setMenuVisible(_:animated:)' was deprecated in iOS 13.0: Use showMenuFromView:rect: or hideMenuFromView: instead How can i solve that? Solution: setMenuVisible(_:animated:)' is deprecated after ios 13.So please use the below code instead of above.         menu. showMenu ( from : cell. superview !,  rect :  CGRect ( x : cell. frame . midX ,  y : cell. frame . origin . y +25,  width : 20,  height : 20))