Posts

Showing posts from September, 2018

NSUserdefault creating multiple file in Preferences folder iOS swift

Solution:  In userdefaults you have to save the small amount of data.If you want to handle large amount of data you have to move to coreData model. Because the app storage size will increase when you save all the data in userdefaults.Then finally the app will crash.Also the OS will kill your app when large amount of storage used.

Build Not visible in iTunes connect after uploading successfully iOS Swift

Solution: If your build had some issues with appicon and launchScreen it will show error during upload to itunesConect. So before upload you must have to check the apicon and Launchscreen. In Appicon must have to check that 1024*1024 icon is exists or not. Also In info.plist file must have to add the user permissions you had already with messages otherwise it will show the same problem also.Like microphone usage,LocationUsage and others....

Passing data between ViewControllers iOS swift

Solution 1: In iOS it's easy to send a data from one view controller to other.If you navigate to the other view controller in that time you want to send a data to the viewController then declare a variable in the next view controller with any Data type like NSMutablearray,String,Int,Double or etc... In the navigation time set the data to that variable like below and navigate let secondController = self.storyboard?.instantiateViewControllerWithIdentifier("ViewController") as LoginViewController secondController.array = self.array self.navigationController?.pushViewController(secondController , animated: true) In secondViewcontroller declare the array variable before the class implementation var array :NSMutableArray! Class LoginViewController:UIViewController { } Solution 2: In other method you can save the data in the userdefaults and synchronize and get that in other ViewController

Swipe gesture for all direction iOS swift

Solution: In iOS you can add a gesture to a particular view in all  4 directions left,right,top and bottom. override func viewDidLoad() {     super.viewDidLoad()     var rightAction= UISwipeGestureRecognizer(target: self, action: "respondSwipe:")     rightAction.direction = UISwipeGestureRecognizerDirection.Right     self.view.addGestureRecognizer(rightAction)     var downAction= UISwipeGestureRecognizer(target: self, action: "respondSwipe:")    downAction.direction = UISwipeGestureRecognizerDirection.Down     self.view.addGestureRecognizer(downAction)     var leftAction= UISwipeGestureRecognizer(target: self, action: "respondSwipe:")    leftAction.direction = UISwipeGestureRecognizerDirection.Left     self.view.addGestureRecognizer(leftAction)     var upAction= UISwipeGestureRecognizer(target: self, action: "respondSwipe:")    upAction.direction = UISwipeGestureRecognizerDirection.Up     self.view.addGestureRecognizer(up

Right swipe in iOS swift like email app

Solution: Before iOS 11 no methods for right swipe.So you can handle it by using swipe gesture with right swipe.And handle in a method.like below for a table View cell     var swipeRight = UISwipeGestureRecognizer(target: self, action: "rightSwipeGesture:")     swipeRight.direction = UISwipeGestureRecognizerDirection.Right     cell.addGestureRecognizer(swipeRight) The method will be like below func rightSwipeGesture(gesture: UIGestureRecognizer) { } But in iOS 11 below method used for right swipe func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {         let swipeAction = self.contextualDeleteAction(forRowAtIndexPath: indexPath)         let swipeConfig = UISwipeActionsConfiguration(actions: [swipeAction ])         return swipeConfig     } If you want the above method not wants to be work at some condition then you can return nil.It will works. func tableView(_

Failed to extract git version from "git -- version" iOS swift error in terminal

Solution: If you are installed new version of Xcode then it will came in command line because in command line tools was not set for xcode. So open your xcode and goto top menu Xcode ->Preference then select Locations below that in command line tools select the current xcode version you use. After that goto terminal then enter "pod init" it will works fine

UserDefaults as common for entire app iOS swift

Solution : In iOS it was easy to create a User default variable as common and get that in entire app. First you have to declare a variable with any name of datatype Userdefaults in Appdelegate funcation at the top. Then in didfinishlaunching initialize the variable and then use it in the entire app.

How to change the layout constraint based on Landscape and portrait mode iOS swift Storyboard

Problem:  I want to design an app with both landscape and portrait mode.In constraint i know its complicated.How can i achieve this? Solution: It's possible when you design with different layout and storyboards.I mean you can design two storyboards for portrait and Landscape if your designs are complicated.Otherwise you can manage by your constraint skills. You can change the storyboard once the user phone layout mode changes.It will workout for Images problems in Layouts design.

iOS Swift Resize a ImageView based on UIImage size and fit the screen's width

Solution: If you resize the image based on imageView the image clarity will be gone.So better you can use the Aspect Fit or scale to fill or Aspect fill instead of resizing the image. Also if you picked the image from gallery must have to get the original size then only clarity never loses.

Get action of myLocation button in GMSMapView iOS swift

Problem: In GMS Mapview there is an option already available for showing the mylocation Button.But it will show in right bottom corner.But i want to create a button with my custom based and add an action to that.Is that possible? Solution: Ya it's absolutely possible.In previously myGMSmapView.settings.myLocationButton = true But in custom button you cannot enable that option.Do as your custom and achieve that. review the below link . https://www.blogger.com/blogger.g?blogID=1352438660899899223#editor/target=post;postID=4882476065633439192;onPublishedMenu=stats;onClosedMenu=stats;postNum=1;src=postname

Save and retrieve the CGPath in CoreData iOS swift

Problem: I want to save the CGpath to the Coredata and retrieve the path and redraw it. Solution: Save to coredata: let objDict = NSMutableDictionary ()                objDict. setValue ( NSKeyedArchiver . archivedData (withRootObject: Color ), forKey: "color" )    let bezierPath = UIBezierPath (cgPath: tool. penPath ) objDict. setValue (bezierPath, forKey: "Path" )    objDict. setValue ( NSNumber (value: Double (tool. lineWidth )), forKey: "width" )              From coredata and redraw: let path = k. value (forKey: "Path" ) let shapeView: CAShapeLayer = CAShapeLayer . init ()   shapeView. path = (path as ! UIBezierPath ). cgPath    shapeView. strokeColor = UIColor . white . cgColor   shapeView. lineWidth = CGFloat (k. value (forKey: "width" ) as ! Double )                      self . ciew . layer . addSublayer (shapeView)

Xcode 10 Error Multiple commands produce

Problem: When i developed my project in Xcode 9.4 after new version of Xcode came i tried to open it in Xcode 10 it shows an error "Xcode 10 Error Multiple commands produce " Solution: 1) Select your project and click on the targets. 2) Select build phases. 3)Under compile sources remove the info.plist 4)Clean your project and run it will works.

How to save the CGRect and color objects in CoreData iOS

Problem: I want to save CGRect for some o my rectangle,Square and other objects.Also i want to save the color object in coreData.If i saved directly in coredata app crashes. Solution: In coredata you may not be able to save the drawing objects and color objects.So follow the steps to solve your problem. 1) Change the coredata attribute type to binary Data 2) Create an NSMutabledictionary. 3) Set integer and double values as NSNumber, Rect as NSValue and color as Data.                     let dic = NSMutableDictionary . init ()                      dic. setValue ( NSValue (cgRect: rect. Button . frame ), forKey: "btnframe" )                      dic. setValue ( NSNumber (integerLiteral:btn. tag ), forKey: "tag" )                      dic. setValue ( NSKeyedArchiver . archivedData (withRootObject: color), forKey: "color" ) 4) Add the dictionary to an array. 5) Then save array to the binarydata using nskeyarchiever like

Change the Name of iOS app in Xcode

Solution: If you want to change the name of your iOS app is not difficult. 1)Goto  target in Xcode. 2)Get the information about your product name 3)Under packaging search the old name and replace it to new Name. Or You can add a new target with new bundle identifier and update.If you don't want to change the bundle identifier then follow the previous way to change it.

Remove null values in an array Objective C || Remove null values in NSMutableArray SWIFT

Solution: If you had a problem with null value in array you can easily remove the null value and change the unstable array stable array. In Objective-C:  [Myarray removeObjectIdenticalTo:[NSNull null]]; In Swift: Myarray = Myarray .filter({ ($0) as AnyObject !== (NSNull()) as AnyObject })