<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ahmed on Medium]]></title>
        <description><![CDATA[Stories by Ahmed on Medium]]></description>
        <link>https://medium.com/@ahmed044?source=rss-4ddf5c8a0b62------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Aq05KlgKpkO5mZgZCMq4gg.jpeg</url>
            <title>Stories by Ahmed on Medium</title>
            <link>https://medium.com/@ahmed044?source=rss-4ddf5c8a0b62------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 08:43:33 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ahmed044/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[A detailed explanation of how ARC works in Swift]]></title>
            <link>https://medium.com/@ahmed044/a-detailed-explanation-of-how-arc-works-in-swift-8076fc79e03b?source=rss-4ddf5c8a0b62------2</link>
            <guid isPermaLink="false">https://medium.com/p/8076fc79e03b</guid>
            <category><![CDATA[apple]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[xcode]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[automatic-reference-count]]></category>
            <dc:creator><![CDATA[Ahmed]]></dc:creator>
            <pubDate>Mon, 12 Jun 2023 22:46:30 GMT</pubDate>
            <atom:updated>2023-06-12T22:46:30.048Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zsiyvq9EdM_y_xZEVXakqA.png" /></figure><p>Automatic Reference Counting (ARC) is a memory management feature in Swift that automatically manages the allocation and deallocation of objects in your code. It helps you avoid memory leaks and manage memory efficiently without requiring manual memory management.</p><h4>How ARC works</h4><p>ARC works by tracking the number of strong references to each object in your code. When an object has no more strong references, it is deallocated and its memory is freed. Strong references are the default type of reference in Swift, but you can also use weak and unowned references to break strong reference cycles.</p><h4>Strong references</h4><p>A strong reference keeps a strong hold on an object, meaning it prevents the object from being deallocated. As long as there is at least one strong reference to an object, it will remain in memory.</p><h4>Weak and unowned references</h4><p>Weak and unowned references are used to break strong reference cycles. A weak reference allows the referencing object to become nil when the referenced object is deallocated. An unowned reference assumes that the referenced object will always have a valid value.</p><h4>Strong reference cycles</h4><p>A strong reference cycle occurs when two or more objects hold strong references to each other. This can prevent both objects from being deallocated, which can lead to a memory leak. Weak and unowned references can be used to break strong reference cycles.</p><h4>Automatic memory management</h4><p>ARC automatically inserts memory management code for you during compilation. This code ensures that objects are deallocated when they are no longer referenced, which helps to prevent memory leaks and improve the performance of your code.</p><h4>Benefits of using ARC</h4><p>ARC provides several benefits, including:</p><ul><li>Efficiency: ARC helps to improve the efficiency of your code by automatically deallocating objects when they are no longer referenced.</li><li>Simplicity: ARC removes the need for manual memory management, which can make your code simpler and easier to maintain.</li><li>Reliability: ARC helps to prevent memory leaks, which can cause crashes and other problems in your code.</li></ul><h4>Below are the code examples of the ARC.</h4><ol><li><strong>Reference Counting</strong></li></ol><pre>class Person {<br>    var name: String<br><br>    init(name: String) {<br>        self.name = name<br>        print(&quot;\(name) is being initialized.&quot;)<br>    }<br><br>    deinit {<br>        print(&quot;\(name) is being deinitialized.&quot;)<br>    }<br>}<br><br>var person1: Person? = Person(name: &quot;John&quot;) // Strong reference<br>var person2: Person? = person1 // Strong reference<br><br>person1 = nil<br>person2 = nil<br>// Output: &quot;John is being initialized.&quot;<br>//         &quot;John is being deinitialized.&quot;</pre><p>In this example, we create an instance of the Person class and assign it to two variables (person1 and person2). Both variables hold strong references to the instance. When we set both variables, the reference count decreases by one each time. Once the reference count reaches zero, the instance is deallocated, and the de-initializer is called.</p><p>2. <strong>Strong References</strong></p><pre>class Car {<br>    var model: String<br><br>    init(model: String) {<br>        self.model = model<br>    }<br>}<br><br>var myCar: Car? = Car(model: &quot;SUV&quot;) // Strong reference<br><br>myCar = nil // Reference count becomes zero, instance is deallocated<br></pre><p>In this example, the myCar the variable holds a strong reference to the Car instance. When we set myCar to nil, the reference count becomes zero, and the instance is deallocated.</p><p>3. <strong>Weak and Unowned References</strong></p><pre>class Person {<br>    var name: String<br>    var dog: Dog?<br><br>    init(name: String) {<br>        self.name = name<br>    }<br>}<br><br>class Dog {<br>    var name: String<br>    weak var owner: Person? // Weak reference<br><br>    init(name: String, owner: Person) {<br>        self.name = name<br>        self.owner = owner<br>    }<br>}<br><br>var person: Person? = Person(name: &quot;John&quot;)<br>var dog: Dog? = Dog(name: &quot;Buddy&quot;, owner: person!) // Weak reference<br><br>person?.dog = dog // Strong reference<br><br>person = nil<br>dog = nil<br>// Output: &quot;John is being deinitialized.&quot;</pre><p>In this example, we have a Person class and a Dog class. The owner property of the Dog class is a weak reference to the Person instance. This prevents a strong reference cycle between Person and Dog. When we set both person and dog to nil, the reference count for the Person instance becomes zero, and the de-initializer is called.</p><p>4. <strong>Strong Reference Cycles</strong></p><pre>class Person {<br>    var name: String<br>    var dog: Dog?<br><br>    init(name: String) {<br>        self.name = name<br>    }<br>}<br><br>class Dog {<br>    var name: String<br>    unowned var owner: Person // Unowned reference<br><br>    init(name: String, owner: Person) {<br>        self.name = name<br>        self.owner = owner<br>    }<br>}<br><br>var person: Person? = Person(name: &quot;John&quot;)<br>var dog: Dog? = Dog(name: &quot;Buddy&quot;, owner: person!) // Unowned reference<br><br>person?.dog = dog // Strong reference<br><br>person = nil // Output: &quot;John is being deinitialized.&quot;<br>dog = nil</pre><p>In this example, the owner property of the Dog class is an unowned reference to the Person instance. It assumes that the Person the instance will always have a valid value. When we set person to nil, the reference count becomes zero, and the Person the instance is deallocated.</p><p>By using ARC, we can focus on writing your code without worrying about manual memory management tasks. ARC automatically manages the memory for us, deallocating objects when they are no longer referenced, and ensuring efficient memory management throughout your application.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8076fc79e03b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Implement Google Sign-In in iOS Apps with the New SDK]]></title>
            <link>https://medium.com/@ahmed044/how-to-implement-google-sign-in-in-ios-apps-with-the-new-sdk-52def1f42184?source=rss-4ddf5c8a0b62------2</link>
            <guid isPermaLink="false">https://medium.com/p/52def1f42184</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[google]]></category>
            <category><![CDATA[xcode]]></category>
            <category><![CDATA[apple]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Ahmed]]></dc:creator>
            <pubDate>Mon, 29 May 2023 23:45:20 GMT</pubDate>
            <atom:updated>2023-05-29T23:45:20.889Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/852/1*sex6qj-vl1g-9YK6Rw-_2g.jpeg" /></figure><p>In the ever-evolving world of iOS app development, staying up-to-date with the latest techniques and technologies is crucial. When it comes to integrating Google Sign-In functionality into your iOS app, the landscape has changed with the introduction of a new SDK version (Version 6.7) of the Google Sign-In API. In this article, we’ll unveil the steps to successfully implement the newest Google Sign-In for iOS, ensuring seamless user authentication and a superior app experience.</p><p>If you want to use the newer version of the Google sign-in API with the older technique, then I’m sorry to announce that it does not work.</p><p>I’m hoping that you know how to get the client id and how to connect your app with the Google console. In case you don’t, follow the tutorial below.</p><p>After successfully connecting your app to Google, It’s time to code. However, a gentle reminder, don’t forget to add the reverse client id to URL types in the target level of your project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jTWnqxfTxl4adoOW" /></figure><p>In the “didFinishLaunchingWithOptions” function of your AppDelegate class, include the following code snippet. This implementation ensures that users will be automatically signed in if they have previously completed a successful sign-in process.</p><pre>GIDSignIn.sharedInstance.restorePreviousSignIn { user, error in<br>            if error != nil || user == nil {<br>              // Show the app&#39;s signed-out state.<br>            } else {<br>              // Show the app&#39;s signed-in state.<br>            }<br>          }</pre><p>Also, don’t forget to add the following functions in the AppDelegate class that will handle all the URL calls from Google.</p><pre>func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -&gt; Bool <br>            return GIDSignIn.sharedInstance.handle(url)<br>        }</pre><p>We are done with the setup. It’s time to implement Google Sign-in in our app.</p><p>Previously, we had to use the sign-in delegate “GIDSignInDelegate” in our sign-in/signup view controller, and we had to conform to it. Moreover, we had to implement its methods. The implementation of the older method is mentioned below.</p><pre>import GoogleSignIn<br>class SignInViewController: UIViewController, GIDSignInDelegate {<br>    <br>    override func viewDidLoad() {<br>        super.viewDidLoad()<br>        <br>        // Set up the sign-in button<br>        let signInButton = GIDSignInButton()<br>        signInButton.center = view.center<br>        view.addSubview(signInButton)<br>        <br>        // Set the delegate<br>        GIDSignIn.sharedInstance().delegate = self<br>    }<br>    <br>    // Implement the sign-in action<br>    @IBAction func signInButtonTapped(_ sender: UIButton) {<br>        GIDSignIn.sharedInstance().signIn()<br>    }<br>    <br>    // MARK: - GIDSignInDelegate methods<br>    <br>    func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {<br>        if let error = error {<br>            // Handle sign-in error<br>            print(&quot;Google Sign-In error: \(error.localizedDescription)&quot;)<br>            return<br>        }<br>        <br>        // Get user details<br>        let userId = user.userID ?? &quot;&quot;<br>        let idToken = user.authentication.idToken ?? &quot;&quot;<br>        let fullName = user.profile.name ?? &quot;&quot;<br>        let givenName = user.profile.givenName ?? &quot;&quot;<br>        let familyName = user.profile.familyName ?? &quot;&quot;<br>        let email = user.profile.email ?? &quot;&quot;<br>        <br>        // Perform further actions with the user details<br>        // For example, you can send the user details to your backend server for authentication or profile creation<br>        <br>        print(&quot;User ID: \(userId)&quot;)<br>        print(&quot;ID Token: \(idToken)&quot;)<br>        print(&quot;Full Name: \(fullName)&quot;)<br>        print(&quot;Given Name: \(givenName)&quot;)<br>        print(&quot;Family Name: \(familyName)&quot;)<br>        print(&quot;Email: \(email)&quot;)<br>    }<br>    <br>    func sign(_ signIn: GIDSignIn!, didDisconnectWith user: GIDGoogleUser!, withError error: Error!) {<br>        // Handle sign-out event<br>        print(&quot;User disconnected&quot;)<br>    }<br>}</pre><p>However, this implementation was only working until Google Sign-in SDK 5. Consequently, in the newer versions (6, 7), the library does not recognize the delegate methods.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_EYw9RdIaRBuVb7F" /></figure><p>In this case, you have two choices.</p><p>1) Downgrade to SDK 5.</p><p>2) Implement/migrate to the newer implementation.</p><p>In the updated implementation, you just have to use one closure, and everything will sort itself out.</p><pre>GIDSignIn.sharedInstance.signIn(withPresenting: viewController) { user, error in<br>    if let error = error {<br>        // Handle error if sign-in fails<br>        print(&quot;Google Sign-In error: \(error.localizedDescription)&quot;)<br>        return<br>    }<br>    <br>    // User is signed in successfully<br>    guard let idToken = user?.user.idToken,<br>          let accessToken = user?.user.accessToken else {<br>        // Handle case when authentication data is missing<br>        print(&quot;Google Sign-In failed: No authentication data&quot;)<br>        return<br>    }<br>    <br>    // Create a GoogleAuthProvider credential using the obtained tokens<br>    let credential = GoogleAuthProvider.credential(withIDToken: idToken.tokenString,<br>                                                   accessToken: accessToken.tokenString)<br>    <br>    // Perform sign-in with the credential using your own services or backend<br>  <br>}</pre><p>That’s it, folks. You have done it. Do consider taking a look at the documentation below to read the migration guide.</p><p>Keep programming fellas…</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=52def1f42184" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[convenience init]]></title>
            <link>https://medium.com/@ahmed044/convenience-init-838b849486b1?source=rss-4ddf5c8a0b62------2</link>
            <guid isPermaLink="false">https://medium.com/p/838b849486b1</guid>
            <category><![CDATA[uikit]]></category>
            <category><![CDATA[xcode]]></category>
            <category><![CDATA[apple]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Ahmed]]></dc:creator>
            <pubDate>Tue, 23 May 2023 23:55:18 GMT</pubDate>
            <atom:updated>2023-05-23T23:55:18.260Z</atom:updated>
            <content:encoded><![CDATA[<p>So I learned a convenient and error-free way of assigning an image to an image view. Previously, I used a hardcoded string to access the image from the assets</p><pre>iv.imageView.image = UIImage(named: &quot;someImage&quot;)</pre><p>However, I thought of accessing images using the dot syntax. My objective was to achieve the following syntax.</p><pre>iv.imageView.image = UIImage(named: .someImage)</pre><p>The dot syntax is easy to use and human error-free. We don’t need to use the hard-coded string explicitly, instead just use the dot to choose an image.</p><p>To achieve this, convenience init arrived as a saviour.</p><p>The convenience init is a special type of initializer in Swift that is used to create a convenience method to initialize an instance of a class or structure.</p><p>Here’s what convenience init means and how it differs from a regular initializer:</p><ol><li>Convenience Initializer:</li></ol><ul><li>A convenience initializer is defined with the convenience keyword before the init keyword.</li><li>It provides an additional way to create an instance of a class or structure that may simplify the initialization process or provide default values.</li><li>Convenience initializers are secondary initializers and must ultimately call a designated initializer of the same class.</li><li>Convenience initializers cannot be overridden by subclasses.</li><li>They are often used to provide more convenient ways to initialize an object or to create alternative initialization paths.</li><li>Convenience initializers are optional and not required for every class or structure.</li></ul><ol><li>Designated Initializer:</li></ol><ul><li>A designated initializer is the primary initializer of a class or structure.</li><li>It is responsible for initializing all properties of the class or structure and ensuring that the object is fully initialized.</li><li>Designated initializers are not prefixed with the convenience keyword.</li><li>They may have parameters and can call other designated initializers of the same class or superclass to delegate the initialization responsibilities.</li></ul><p>In summary, a convenience init is a secondary initializer that provides a more convenient or alternative way to create an instance of a class or structure. It must call a designated initializer of the same class to ensure that all properties are properly initialized.</p><p>Here are a few steps one needs to take to choose the images using the dot syntax.</p><p>1) Creating an enum of type string that will hold the actual name of the image. The value is then mapped to its corresponding key.</p><p>For example</p><pre>enum ImageName: String {<br><br>    case message = &quot;Message&quot;<br><br>    case lock = &quot;Lock&quot;<br><br>    case appLogo = &quot;AppLogo&quot;<br><br>}{</pre><p>2) After that, just extend the UIIMage and add the convenience init.</p><pre>extension UIImage {<br><br><br>    convenience init(named imageName: ImageName) {<br><br>        self.init(named: imageName.rawValue)!<br>       }<br>}</pre><p>3) Now, Just access the images through dot syntax.</p><pre>iv.imageView.image = UIImage(named: .message)</pre><p>Thats all.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=838b849486b1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The journey from an Android developer to an iOS developer]]></title>
            <link>https://medium.com/@ahmed044/the-journey-from-an-android-developer-to-an-ios-developer-4a5b210a115f?source=rss-4ddf5c8a0b62------2</link>
            <guid isPermaLink="false">https://medium.com/p/4a5b210a115f</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[apple]]></category>
            <category><![CDATA[android-studio]]></category>
            <category><![CDATA[development]]></category>
            <dc:creator><![CDATA[Ahmed]]></dc:creator>
            <pubDate>Wed, 14 Sep 2022 18:55:20 GMT</pubDate>
            <atom:updated>2022-09-14T18:55:20.227Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*RrGAqZEM0i_a-kujMI7p2A.png" /></figure><p>Android development has been a renowned development, especially in South Asia. The reason for the above fact is the number of android users in that region. Consequently, freshers and novice developers prefer to opt for android development.</p><p>Similarly, I also started my career as an android developer. My first app was a calculator, followed by the Whatsapp clone, then the surveillance app, and so on…, but still I was not confident about my android development skill. The following were the major reasons for my inferiority in android development.</p><h3><strong>Complex syntax and hectic implementations</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kgksmfCzC47qZFgx6p0qCg.png" /></figure><p>No matter how simplified the Kotlin language for android development is, the framework and implementation of android development are still quite complex for newbies. Let’s take an example of the recycler view, the recycler view is used to present a data set. if you want to display large data set in your app, you should use the recycler view. However, the implementation of the recycler view is too difficult. Below are the steps to implement a simple recycler view.</p><ol><li>Define a model class to use as the data source.</li><li>Add a RecyclerView to your activity to display the items.</li><li>Create a custom row layout XML file to visualize the item.</li><li>Create a RecyclerView.</li><li>Bind the adapter to the data source to populate the RecyclerView.</li></ol><p>Moreover, the complexity of working with fragmentation is immeasureable.</p><p>Contrary to android development, it is super easy to implement the tableview(an alternative to recycler view in Ios) in iOS development.</p><h3><strong>Kotlin or Java, which language to choose</strong></h3><p>As a beginner to development, one might wonder which language to choose for the android development. Both the languages mentioned above have pros and cons,therefore, for the novice,its difficult to choose the language. However, android annouced Kotlin as their official language, however, most of the developers still using Jave and most of the libraries are being written in the Java. Further, android jetpack, which is the latest and intuitive way to make UI only supports Kotlin. Consequently, if you are a java developer, new features wont be available to you.</p><p>Contrary to this , apple was using objective C as their primary language, however, they completely shifted to Swift.</p><p>Swift is far more easier and developer friendly as compare to Kotlin.</p><h3>So many devices to design a UI for, ughhh</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*q96hhVlvOH1lAX63D4IVOg.jpeg" /></figure><p>Almost every mobile phone company uses android as their operating system, resultant , tens of different phone designs, different screen sizes. Designing the front end becomes difficult because of numerous screen sizes. Now they have folding phones, as well as the flip ones. Resultant, you need to put extra effort to make responsive view.</p><p>Contradictory to android, apple only has few screen sizes and they resembles to one other, making it easier for the developer to design.Moreover, similar to android apple also supports numerous different way to design a front end of an application:</p><ol><li>Storyboards(Drag and drop).</li><li>Desiging through the swift langauge.</li><li>SwiftUI.</li></ol><h3>Crowded market of android developers</h3><p>The software developer market is flooded with the android developers, especially in the asian region. Almost 90 percent of the students of computer science make their final project in android , thus they pursue the career as an android developer. One good reason for the immense popularity of android development that one doesn&#39;t need to buy expensive apple products. Due to this reason, the demand of android developer is lesser compares to iOS developer(iOS developers comparivietly earn more).</p><h3><strong>Takeaway for the beginners</strong></h3><p>Although iOS development does have pros and cons,but I found it relatively much rewardful than any other development. Contrary,if you are new to development or programming and cannot afford mac and Iphone and apple development program, start learning and developing android applications. It will sharpen your development and programming skills,moreover, migration to iOS development becomes easier if you know one or two developments.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4a5b210a115f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Leading, Trailing vs Left, Right Constraints]]></title>
            <link>https://medium.com/@ahmed044/leading-trailing-vs-left-right-constraints-c315e6f92aa9?source=rss-4ddf5c8a0b62------2</link>
            <guid isPermaLink="false">https://medium.com/p/c315e6f92aa9</guid>
            <category><![CDATA[xcode]]></category>
            <category><![CDATA[autolayout-constraints]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[constraints]]></category>
            <category><![CDATA[localization]]></category>
            <dc:creator><![CDATA[Ahmed]]></dc:creator>
            <pubDate>Sat, 04 Dec 2021 13:47:20 GMT</pubDate>
            <atom:updated>2021-12-04T13:47:20.884Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/313/1*8Ly0gZT165qIJ_PRXUW7YA.jpeg" /></figure><p>The image above evidently expresses the same emotion when we see leadingAnchor and leftAnchor. After spending some time on Xcode and obviously on google, I found a clear and most important difference between leading, trailing, and left, right anchor. This concept is really useful in localization when you are dealing with languages such as Arabic because it is a right to left language.</p><p><strong>Left and Right constraints</strong></p><p>Left and Right constraints are absolute, they will always refer to the left/right of the screen or the control, both are strongly fixed and always depend on the left and right sides of the screen.</p><p><strong>Leading and Trailing constraints</strong></p><p>Leading and trailing constraints are affected by the device locale; In locales where the reading direction is left to right (English, French, Spanish, and so on) leading &amp; left (and trailing &amp; right) can be used interchangeably. In locales where the reading direction is right to left (e.g Hebrew, Arabic) then ‘leading’ will be the right side, and ‘trailing’ will be the left side.</p><p><strong>When to use Left and Right constraints?</strong></p><p>While using localization, Apple automatically does numerous stuff. For example, if you are localizing your app in English and Arabic, it will automatically change the leading to right and trailing to left. Contrary, if you want your constraint to remain the same way in the case of both English and Arabic, you would use the leftAnchor and rightAnchor instead of leading and trailing.</p><blockquote><em>class ViewController: UIViewController {</em></blockquote><blockquote><em>override func viewDidLoad() {</em></blockquote><blockquote><em>super.viewDidLoad()</em></blockquote><blockquote><em>NSLayoutConstraint.activate([</em></blockquote><blockquote><em>titleLabel.leadingAnchor .constraint(equalTo: roundedView.</em><strong><em>leadingAnchor</em></strong><em>, constant: 20),]) }</em></blockquote><blockquote><em>}</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8dW7KFcAW0_odfHS7QXsXQ.png" /><figcaption><strong>constraints</strong> using the leading anchor (English)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IU82SvXklau50betQd9SLw.png" /><figcaption><strong>constraints</strong> using the leading anchor (Arabic)</figcaption></figure><p>Noticed, how Xcode automatically has automatically changed the alignment of a text. The above snippets visually explain how leading changes its alignment to the right when the app is localized to Arabic.</p><p><strong>Now we are using leftAnchor instead of leading.</strong></p><blockquote><em>class ViewController: UIViewController {</em></blockquote><blockquote><em>override func viewDidLoad() {</em></blockquote><blockquote><em>super.viewDidLoad()</em></blockquote><blockquote><em>NSLayoutConstraint.activate([</em></blockquote><blockquote><em>titleLabel.leadingAnchor .constraint(equalTo: roundedView.</em><strong><em>leftAnchor</em></strong><em>, constant: 20),]) }</em></blockquote><blockquote><em>}</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8dW7KFcAW0_odfHS7QXsXQ.png" /><figcaption><strong>constraints</strong> using the Left anchor (English)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*olUIWvjD1dkdXYzHz9kTBA.png" /><figcaption><strong>constraints</strong> using the Left anchor (English)</figcaption></figure><p>Yeah yeah, I know that you get a point that using leftAnchor constraint didn&#39;t let the Xcode to change the alignment automatically.</p><p>I hope you found this useful. Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c315e6f92aa9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[iOS localization]]></title>
            <link>https://medium.com/@ahmed044/ios-localization-e30c5da7166a?source=rss-4ddf5c8a0b62------2</link>
            <guid isPermaLink="false">https://medium.com/p/e30c5da7166a</guid>
            <category><![CDATA[localization]]></category>
            <category><![CDATA[translation]]></category>
            <category><![CDATA[xcode]]></category>
            <category><![CDATA[swift-language]]></category>
            <category><![CDATA[translate]]></category>
            <dc:creator><![CDATA[Ahmed]]></dc:creator>
            <pubDate>Sun, 28 Nov 2021 15:13:12 GMT</pubDate>
            <atom:updated>2021-11-30T17:16:49.702Z</atom:updated>
            <content:encoded><![CDATA[<p>Localization is the most common way of making your application support different dialects. As a rule, you make your application with an English UI first and afterward localize the application to different languages like German. Localizing an application is shockingly easy in iOS, and actually, the crucial step is ensuring you get all your text deciphered by local speakers of your objective languages.</p><p>You need to do a few steps to localize an application, this include.</p><ol><li>Create a String file.</li><li>Add your desired language at the project level.</li><li>Add your data(translated words) in a string file.</li><li>Localize your labels, buttons, text view, etc.</li></ol><p><strong>Create a String file</strong></p><p>The first step is to create a string file and name it <strong>Localizable.strings</strong>, make sure to use the exact same name otherwise Xcode won&#39;t be able to locate the file, in short, no translation. For now, leave the string file as it is, we will come back to it soon.</p><p><strong>Add your desired language at the project level</strong></p><p>Now the most crucial step is to let Apple knows what languages you will use in your app. The English language is the default language to select more languages, you need to head towards your <strong>project file</strong> in Project Navigator, and select your project in the project and targets list. Open the <strong>Info</strong> tab, and click the “+” button under the <strong>Localizations </strong>section. Then choose a language you want to support from the dropdown list displayed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Stpm7crcU91jD2UwrkGXeg.png" /></figure><p>After you add the language(s), you will see your string may look like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZU-QdZQP3KQWBJ9PB7zj7A.png" /></figure><p><strong>Add your data(translated words) in a string file</strong></p><p>Now that you have more than one string file based on the language selection you made earlier, it&#39;s time to keep a few things in mind.</p><p>Each word needs a unique string name, let say ‘Hello’ in English may have a string name <strong>Hello, </strong>and its german translation is ‘Hallo’, but the string name of it will be <strong>Hello</strong>. The snippet below will make things more apparent.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9VU2hAF4QGIheTH2BaKi2Q.png" /></figure><p><strong>Localize your labels, buttons, text views</strong></p><p>After completing your translation string fie, it&#39;s time to localize views and make them automatically translated based on the language. To do that, you need one line of code, and that magic code is <strong>NSLocalizedString(“key”, comment: “comment”)</strong>. where the key is the name of the name and comment is any relevant information you want to embed, but a comment is mostly an empty string. Thus, if you want to localize a label with the title “Welcome”, this is how you are going to do it.</p><blockquote>LabelName.text = NSLocalizedString(“welcome_screen_title”, comment: “”)</blockquote><p>That&#39;s it, that&#39;s all you need to localize your app.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e30c5da7166a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>