Posts

Showing posts from November, 2018

Set the slider value based on the AVAudiosession volume || mobile system volume based slider change in iOS swift

Solution: If you are adjusting the volume in your phone volume button based on slider change you can follow the below steps     override func viewDidDisappear( _ animated: Bool ) {         AVAudioSession.sharedInstance().removeObserver( self , forKeyPath: "outputVolume" )         do { try AVAudioSession.sharedInstance().setActive( false ) }         catch { debugPrint( " \ ( error )" ) }     }          func listenVolumeButton() {         let audioSession = AVAudioSession.sharedInstance()         do {             try audioSession.setActive( true )         } catch {             print( "some error" )         }         audioSession.addObserver( self , forKeyPath: "outputVolume" , options: NSKeyValueObservingOptions.new, context: nil )     }          override func observeValue(forKeyPath keyPath: String ?, of object: Any ?, change: [ NSKeyValueChangeKey : Any ]?, context: UnsafeMutableRawPointer

How to disable the selection in TableView iOS swift?

Solution: If you want to disable the selection for entire tableView then use the below code for that. tableView.allowsSelection = NO; Or you can use the below code cell.selectionStyle = UITableViewCellSelectionStyle.None If you want to disable the selection for particular row you can do that in cell for row function disable the userinteraction for the cell. Cell. UserInteractionEnabled = false

How to embed custom font in iPhone application?

Solution: Xcode 10 or greater if you add the font files into the project and it will be added directly when you try to set font in storyboard it will be listed. But in previous time it was not possible.First you have to add the font file to your project. After that open the Info.plist file and set the key named  UIAppFonts change the datattype to array and set the each fontfilename into that you had added already. Save the Info.plist file [UIFont fontWithName:@"CustomFontName" size:12]   Then use the font as above.

Delete a record in iPhone addressBook iOS swift

Solution: You can have to store the contact identifier in your database.Using that contact identifier you can navigate the app to view the contactEdit page.It can have an option to delete the contact

Difference between Synchronous and Asynchronous in iOS swift?

Solution: Synchronous: Synchrounous waits until the process finished after that only the next process will continue executing. It will be waiting to the user to complete the previous task. Asynchronous: Asynchronous will be the simultaneous execution of process.Like another process will not wait for that process.It will be executing in the background.After the completion we can display the process result with its data. For example loading the image in the tableView will be executed using the asynchronous task because user don't want to wait for the result of image it will be loaded in the background. 

App crashes when i try to delete a row in TableView iOS swift

Solution: If you are tried to delete the row and not delete the element from array it will be occurres. So first you have to execute the delete row code then remove the indexpath.row element from array then reload the table.It will works

How to get the inBetween days from fromdate and Todate in iOS swift?

Solution: If you want to get the everyday from between tow days then follow the below code you can proceed with that. You can give the Extension as date and get the function using the below code. Code: Class Viewcontroller:UIViewController { } extension Date {     func inBetweenDates(fromDate: Date ,toDate: Date ) -> NSMutableArray {         let dateArray = NSMutableArray ()         var from = fromDate                  while from <= toDate {             var dates: Date = from             dates = truncateSecondsForDate (fromDate: dates)             dateArray. add (dates)             dates = from. addingTimeInterval ( 60 * 60 * 24 * 1 )             from = dates         }         return dateArray     } }

Remove Duplicate element in an NSMutableArray iOS swift

Solution: In NSMUtablearray we can have to save the array of data or add a data to that array.But it will accept the duplicate elements.It cannot have primary keys to restrict that.So you can follow the below code to remove the duplicate elements in the final moment. func removeDuplcate(arr: NSMutableArray )-> NSMutableArray {         let temp: NSMutableArray = NSMutableArray ()         for i in 0 ..<arr. count {             if !temp. contains (arr[i]) {                 temp. add (arr[i])             }         }         return temp     }

Get an image from it's name from Document directory iOS swift

Solution: If you saved an image to document directory in your app you cannot have to save the full url path to your database or coredata. Because every time document directory path will be modified.So you can save the image name in your database and fetch it later using the below code. func getImage(name: String )-> UIImage {         let fileManager = FileManager . default         let imagePAth = ( NSSearchPathForDirectoriesInDomains (. documentDirectory , . userDomainMask , true )[ 0 ] as NSString ). appendingPathComponent (name)         if fileManager. fileExists (atPath: imagePAth){             if UIImage (contentsOfFile: imagePAth) != nil {                 return UIImage (contentsOfFile: imagePAth)!             } else {                 return   imageLiteral(resourceName: "default image you saved")             }         }         else {             return   imageLiteral(resourceName: "default image you saved")  

Set the navigation bar color in UIIMagePicker for my app theme color iOS swift

Solution: You can use the below code to set the navigation bar colour for the imagepicker from your app app. extension UIImagePickerController {     open override func viewWillLayoutSubviews() {         super . viewWillLayoutSubviews ()                  self . navigationBar . topItem ?. rightBarButtonItem ?. tintColor = UIColor (). white//here you can put your app theme color         self . navigationBar . topItem ?. rightBarButtonItem ?. isEnabled = true              } }

UITabbar shows syrinc when i went to background and enter into foreground in my app iOS swift

Solution: In iOS 11 it has a bug so try the below code in appdelegate it will works good. class TabBar: UITabBar {     private var cachedSafeAreaInsets = UIEdgeInsets.zero          override var safeAreaInsets: UIEdgeInsets {         if #available ( iOS 11.0 , *) {             let insets = super .safeAreaInsets             if insets.bottom < bounds.height {                 cachedSafeAreaInsets = insets             }         } else {             // Fallback on earlier versions         }         return cachedSafeAreaInsets     } }

Is that possible to set a primary key in CoreData iOS swift?

Solution: There is no primary key available in coredata.It has more than a database.It will had relationShips and entities. If you want to implement primary key then you can do onething to store an identifier with Integer and use it as primary key.But you cannot be set as primary key in coredata. So you can do that fetch the data from coredata with predicate and check that identifier is available or not then save it in coredata.

Implement to get fetch the data from Contacts and implement the search in firstName,LastName and phone numbers

Solution: You cannot be able to search the firstName,LastName and phone number in contacts List because it is a dictionary with multitypes.So predicate will not be possible.So you can get the contact and save it in a dictionary with firstName and LastName as two keys and phone number as one key with concatenating the all phonenumbers in a single contact as a string and implement the search in the dictionary will works good.

What is strong and weak properties in iOS ?

Solution: Strong: Strong is used to describe a property that will never be return nil.It must had an amount of data.For example if you referred the Employer to employee you can do it as strong relationship. Weak: Weak is used to describe a property that if it returns nil or it will returns a data.It will never be a strong value.You can refer from employee to employer it will be less connected.

Coredata data storing types iOS swift

Solution: In most of the time we are storing the Coredata as in sql format.But it had different type to save the data. XML Binary Sqlite In-Memory NSpersistant store is commonly used for storing and retrieving the data in coredata.You can use sortdescriptors to fetch the organized data based on the attributes.

iOS 9 pdf file not able to show to the user

Solution: After iOS 10 only the apple provides the feature for file manager. So you have an access for listing the file that are stored in your device. But if you want to show the PDF file to the user then you can use webView inside your app and get the url and open it in the webView. But file listing is not possible before iOS 10.

Difference between cross platform and Native in iOS and android

Solution: Native: iOS : In native app development you can have their own tool to develop and distribute the app like in iOS Xcode is available.In android android Studio is available. In iOS we are using the design as with xml language with it UI tools like label and button.Development to control the design and action are made by two languages.One is objective C and Swift languages. It will provide the development and distribution based environment for the user. Android: In android we can using xml language for design purpose Java for development purpose.Now a days we are also using kotlin for development. Cross Platform: Cross platforms are used for single development and multiple type of deployment.So we can develop the apps and distribute to multiple environment like iOS,Android,Windows,Ubuntu,... In that cross platform you can design by using HTML and Javascript and develop by Javascript. Cordova is maximum used. Phonegap Titanium iOnic are the tools t

iOS swift variable value came as optional

Solution: In swift it has two type of objects one is unwrapped and another one is wrapped. Unwrapped: let name = nameValue as? Int Wrapped: let name = nameValue as! Int If you tried with unwrapped then it will came as optional value.So if you can use as wrapped format it will came with original value. One more thing that if you assigned other datatype value then unwrapped function will not force close your app.Because it will skip the data if not matches the data type. In wrapped format it will force closes your app when you assigned the other datatype values.

# Pragma mark in Swift || Annotations in swift

Solution: In swift you can use the annotations for code folding and formatting.You can easily access your need of line using pragma marks. //  MARK :- Title for identification // write your codes here It will format your code via the title you had given

How to get the selected row or selected cells in UITableView iOS swift

solution: You can get the selected rows or selected cells by using the below code.It will return the array of indexPath.You can get and set it by using the arrays. For selected Rows: let selected = tableView.indexPathsForSelectedRows For selected Sections: let selected = tableView.indexPathsForSelectedSections

Remove a particular notification from notification tray iOS swift

Solution: Yes it's definitely possible.If you have an option to save the notification identifier in your database or coredata then it's easy. You can find the notification from the scheduled notification of your app.             UNUserNotificationCenter .current().removeDeliveredNotifications(withIdentifiers: [ids])

How to save the image as string from my textView or TextField and display it in iOS swift

Solution: In iOS you can easily set the emoji stickers to the textField because they already accepting the emoji in textfileds. Follow the below steps to easily set the home emoji to your textfield. 1) First you have to convert that image to string.Its not a big problem.Just you have to set it between "".That's it. 2)If you had a textfield named nameTF then you just set the emoji as below nameTF.text = "🏠"

Font name is already set but not changed for the text iOS swift

Solution: If you set the font to your textfield with font name then must be double check it.If you set the wrong font then only it came as HelverticaNue as default font. Must set the correct name.

Set the Italic to the UITextView iOS swift

Solution:     @IBAction func didTapOnItalic( _ sender: Any ) {         let textV = self . TextView         if  textV != nil {                          var fonts = textV. font              fonts = (fonts?. isItalic )! ? fonts?. removeitalic () : fonts?. setItalic () textV. fontName =  fonts!. fontName          }     } extension UIFont {     var isItalic: Bool     {         return fontDescriptor . symbolicTraits . contains (. traitItalic )      }     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 )          }     } func remo

Set bold to one UITextView iOS swift

Solution: The below function is used for set the bold to the TextView.     @IBAction func didTapOnBold( _ sender: Any ) {         let  textView = TextView         if  textView != nil {             var fonts = textView. font             fonts = (fonts?. isBold )! ? fonts?. removeBold () : fonts?. setBold () textView.font =  fonts!. fontName         }     } extension UIFont { var isBold: Bool     {         return fontDescriptor . symbolicTraits . contains (. traitBold )      } //set the bold 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 )         }

Get the Indexpath from button action of one cell iOS swift

Solution: If you had already added an action to one button or switch then you can easily get the indexPath for that button using the below function.Code extension UITableView { func indexPathForView(view: AnyObject ) -> NSIndexPath ? {         let originInTableView = self . convert ( CGPoint . zero , from: (view as ! UIView ))         return self . indexPathForRow (at: originInTableView) as ! NSIndexPath     } } You can add the above extension for tableView and get the indexPath.You can call the function inside the button action like below.      @IBAction func didTapOnSwitch( _ sender: AnyObject ) {         let swit = sender as ! UISwitch         let index = self . myPlacesTbl . indexPathForView (view: swit) }

How to check is UITextView is underlined or not iOS swift

Solution: You cannot have any functions to check that.But you can test it by using the below method     func attributes(value: Int ) -> NSAttributedString {         let textV = self . TextView         let newTextView: UITextView ! = UITextView . init ()         var attrs = [ NSFontAttributeName :  self . TextView . font ,                      NSForegroundColorAttributeName :  self . TextView . textColor ,                      NSUnderlineStyleAttributeName : value] as ! [ String : Any ]         var attributedString = NSMutableAttributedString (string: "" )         let buttonTitleStr = NSMutableAttributedString (string:( self . TextView . text )!, attributes:attrs)         attributedString. append (buttonTitleStr)         newTextView. attributedText = attributedString         return newTextView. attributedText     } In your textview you can check it by using the below code             let attributedString = self