Search Your Question

Showing posts with label XCode. Show all posts
Showing posts with label XCode. Show all posts

Identifying Memory Leaks using the Xcode

Identifying Memory Leaks in Xcode with Memory Graph Debugger is a great way to make application leakage proof. When it comes to detecting memory leaks in iOS development using Xcode, there are a few steps you can follow. Memory leaks can lead to performance issues, crashes, and an overall degraded user experience. Therefore, it is crucial to address and resolve them.

Identifying Memory Leaks in Xcode with Memory Graph Debugger.

1. Enable the Memory Debugging Tools:
   - Open your Xcode project and go to the "Product" menu.
   - Select "Scheme" and then click on "Edit Scheme."
   - In the left sidebar, select "Run" and then navigate to the "Diagnostics" tab.
   - Enable the "Memory Management" option and close the scheme editor.

2. Run the App with the Leaks Instrument:
   - Build and run your iOS app in the Xcode simulator or on a physical device.
   - Go to the "Product" menu and select "Profile."
   - Choose the "Leaks" instrument.
   - Observe the instrument while interacting with your app to detect any memory leaks.
   - If any leaks are found, it will be indicated in the "Allocations List" and "Leaks List" panels.

3. Analyze the Detected Leaks:
   - Click on the leaks listed in the "Leaks List" panel to review them in detail.
   - The "Allocations Summary" panel will show you the memory allocations and deallocations for each object.
   - Analyze the call stack to identify the source of the leak.
   - Pay attention to any objects that are not being deallocated when they should be.

4. Diagnose the Memory Leak:
   - Understanding the code responsible for the memory leak is key to finding a solution.
   - Use the call stack information and Xcode's debugging tools to trace back to where the leaked object is created or retained.
   - Review variables and references that may be keeping the object from being released.
   - Common causes of memory leaks include strong reference cycles, forgotten timers, delegates not set as weak, or improper use of closures.

5. Fix the Memory Leak:
   - Once you've identified the source of the memory leak, take appropriate actions to fix it.
   - Ensure that objects are properly deallocated by removing any unnecessary strong references.
   - Consider using weak or unowned references where appropriate.
   - Review your code for strong reference cycles and break them using capture lists or weak/unowned references.
   - Validate that the memory leak is resolved by re-running the app and using the Leaks instrument again.

By following these steps, you can effectively detect and fix memory leaks in your Xcode project. Regularly checking for and resolving memory leaks will result in a more stable and efficient iOS .

Enlist different background modes

Ans : 

There are different background modes provided from apple and we can see them under Signing & Capabilities > + Capability (New) > Background Mode

Switch on background mode and select which is required in our project.

Background Modes in iOS

  1. Audio, AirPlay and Picture in Picture
  2. Location updates
  3. Void over IP
  4. External accessory communication
  5. Uses Bluetooth LE accessories
  6. Acts as a Bluetooth LE accessory
  7. Background fetch
  8. Remote notifications
  9. Background processing

For tutorial, I recommended article 

How to call segue programmatic?

Ans : 

For segue first, We have to set identifier in Class Inspector right side in XCode. Through that identifier, we can call like

performSegue(withIdentifier: "identifier", sender: nil) 

What is Content Hugging and Content Compression Resistance Priority?

Ans : 

The priority really come in to play only if two different constraints conflict. The system will give importance to the one with higher priority. So, Priority is the tie-breaker in the autolayout world.

1. Content Hugging Priority : 

Larger the content hugging priority , the views bound will hug to the intrinsic content more tightly preventing the view to grow beyond its intrinsic content size. Setting a larger value to this priority indicates that we don’t want the view to grow larger than its content.

In above example, we set both label leading, trailing, top and bottom but not set width constraint. So here conflicts will occur. You can see red line between two label showing conflict.

Solution : If we have label's content hugging priority higher than there will be no conflicts as hight priority label will not grow its size more than its content size. See below image :

Blue label has more content hugging priority (251) than green label(250). Blue label's width will be set fixed as its content size.

2. Content Compression Resistance : 

Setting a higher value means that we don’t want the view to shrink smaller than the intrinsic content size. It's simple : Higher the priority means larger the resistance to get shrunk.

Example . One button having large name and auto layout is set on button as its width is become 40. So, button's content is not readable. See image :
Button horizontal compression resistance is 750 and width constraint priority is 1000.

For Solution, let's change horizontal compression resistance to 1000 and width constraint priority less than 1000 i.e 999 . Now see effect on below image :
Button horizontal compression resistance is 1000 and width constraint priority is 999.

If you have any comment, question, or recommendation, feel free to post them in the comment section below!

What are the app id and bundle identifier?

Ans : 
Bundle ID : 
A bundle ID or bundle identifier uniquely identifies an application in Apple's ecosystem. This means that no two applications can have the same bundle identifier. To avoid conflicts, Apple encourages developers to use reverse domain name notation for choosing an application's bundle identifier.
i.e com.iosiqa.newapp or

App ID : App ID consists of Team ID + Bundle ID. Team ID is provided by apple to one team in developer account.

What is use of APP ID? 
Whenever you want to enable a capability or application service for your application, you enable that capability for the App ID your application is linked to. This used to be tedious, requiring a visit to Apple's developer website. Xcode has evolved quite a bit over the years and it takes care of the details most of the time.

Latest version of iOS, Swift, XCode

Ans : 
As per today (18-Oct-2018),

Latest version of

XCode : 10.0
Swift : 4.2
iOS : 12.0
Mac OS : mojave 10.14
Objective C : 2.0

I am using XCode 9.3, Swift 3.0, iOS 11 and mac os as High sierra.

Swift Version History :

2014-09-09Swift 1.0
2014-10-22Swift 1.1
2015-04-08Swift 1.2
2015-09-21Swift 2.0
2016-09-13Swift 3.0
2017-09-19Swift 4.0
2018-03-29Swift 4.1
2018-09-17Swift 4.2

What is size class? Explain with Example.

Ans : 
Size Classes are groups of screen sizes that are applied to the width and height of the device screen. The two Size Classes that exist currently are Compact and Regular.

The Compact Size Class refers to a constrained space. It is denoted in Xcode as wC (Compact width) and hC (Compact height).

The Regular Size Class refers to a non-constrained space. It is denoted in Xcode as wR (Regular width) and hR (Regular height).

iPhone : Most iPhone devices will use the Compact width (wC) size class in each orientation with some exceptions.
The iPhones 6/7 Plus can inherit the Regular width (wR) size class resulting in the ability to use functionality normally reserved for the iPad, such as the split-view pane. Split-VIew pane is speciall made for iPad.

iPad : All iPad devices use the Regular width (wR) size class regardless of landscape or portrait orientation. In both horizontal and vertical landscape, the iPad will use a split-view pane to take advantage of the available screen space because it falls within this unconstrained size class.

Controlling the UI with Size Classes

In most cases, specifying the width class is sufficient when laying out your app; however, you can use the height class to customize your app as well. For example, if you use a split-view pane in an iPad app, users will see the same pane on iPhone Plus in landscape orientation because they both inherit the Regular width (wR) size class.

If that is not your intention, you can exclude a split-view pane from appearing on the 7 Plus by specifying both the width and height Size Classes. This works because the height of an iPhone Plus in landscape orientation is compact (hC) while all iPad devices have a regular height (hR).

You can also use Size Classes to target specific UI elements like font colors, font sizes, drop shadows, view colors and more to adapt to users’ device screen. These variations give you added control as to how your UI can adapt to different devices and orientations that your user may be using.