<?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 Аλέξιος on Medium]]></title>
        <description><![CDATA[Stories by Аλέξιος on Medium]]></description>
        <link>https://medium.com/@alimovlex?source=rss-e5dff74a54de------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*IFNAbrKJDMKRbs4x-tBuGA.jpeg</url>
            <title>Stories by Аλέξιος on Medium</title>
            <link>https://medium.com/@alimovlex?source=rss-e5dff74a54de------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 02:56:53 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@alimovlex/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[Mastering the fundamentals of Google Protocol Buffers using C++]]></title>
            <link>https://alimovlex.medium.com/mastering-the-fundamentals-of-google-protocol-buffers-using-c-8452b515c3e0?source=rss-e5dff74a54de------2</link>
            <guid isPermaLink="false">https://medium.com/p/8452b515c3e0</guid>
            <category><![CDATA[socket-programming]]></category>
            <category><![CDATA[iot]]></category>
            <category><![CDATA[cpp]]></category>
            <category><![CDATA[tcp]]></category>
            <category><![CDATA[protobuf]]></category>
            <dc:creator><![CDATA[Аλέξιος]]></dc:creator>
            <pubDate>Mon, 12 Aug 2024 16:24:46 GMT</pubDate>
            <atom:updated>2024-08-12T16:24:46.435Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*WRYLQp4qxQ70wVtb.png" /><figcaption>Picture 1 — The Google Protocol Buffers diagram by <a href="https://medium.com/@dineshchandgr">dineshchandgr</a>.</figcaption></figure><p>Last year, I was assigned a task to port the existing Objective-C iOS application for managing external IoT devices based on Google’s Protocol Buffers. I hesitated because I was a tyro in serialization processes. Although I had this conundrum and involved task, I have finished it! Besides, the data serialization seems more straightforward for me now than before, so I will be grateful to share my knowledge about it here.</p><p>Let us start with the definition of data serialization. According to “<a href="https://devopedia.org/data-serialization">Devopedia</a>” website, it means the following:</p><blockquote>Data serialization is the process of converting data objects present in complex data structures into a byte stream for storage, transfer and distribution purposes on physical devices.</blockquote><p>Similarly, the opposite process is called <em>deserialization. </em>These process are depicted in the following diagram below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*5vI7ityUA5UzZPfY.jpg" /><figcaption>Picture 2 — The data serialization and deserialization diagram by <a href="https://devopedia.org/data-serialization">Devopedia</a></figcaption></figure><p>Therefore, it is the simple way of transmitting objects between programming languages through proto files.</p><p>By the way, if you know already the ways of serializing data using json and xml apart protobuf, I am positing on protobuf’s feasibility in your project. Here are the pros and cons of usining protocol buffers.</p><h3>Advantages of Protobuf:</h3><ul><li>High performance during the process of deserialization.</li><li>Straightforward schema. The primary and secondary things can be easily distingueshed.</li><li>Low data consumption. Irrefutably, it is significant when internet provider has expensive tariffs.</li><li>Support of many widely-known languages like Java, Python, Objective-C, Ruby, and latest version (proto3) also supports Dart, Go, Ruby and C#</li></ul><h3>Disadvantages of Protobuf</h3><ul><li>The candid schema is mandatory. If the data schema is mutable at run-time, the JSON will be the better option.</li><li>Although the popular languages are supported, others are not.</li><li>The community support for Protobuf is tiny compared to JSON or XML.</li></ul><p>If you still consider going with Google’s protocol buffers, I will be glad to elaborate on this topic. So, here is the structure of a proto file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*tQY8gHZDYDxdwQtp.png" /><figcaption>Picture 3 — The proto file structure by @bnarasapur</figcaption></figure><p>The syntax of a proto file is simple. The field in .proto files can be defined as optional or repeated or default due to the implicit presence in proto3 syntax. Moreover, the data type has to be specified such as integer, boolean or floats.</p><p>Furthermore, let us make our first transmission of this proto message via elementary TCP protocol using client-server application.</p><p>To build this application, the protobuf compiler is needed. Usually, it is named protoc but depending on your package manager the tool name might differ. Anyway, I assume that the user has debian-based linux distro installed and can install this package with the following command.</p><p>sudo apt install protobuf-compiler</p><p>As soon as the <em>protoc </em>command is available in the shell, the <em>person.proto </em>can be compiled with this command.</p><p>protoc person.proto --cpp_out .</p><p>Hence, there is the output of the command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/296/1*cYupxtI26clAS7Ji5XajIg.png" /><figcaption>Picture 4 — Protobuf compiled files.</figcaption></figure><p>Additionally, let us pick up the example of a client-server app and add modifications consisting of serialization and deserialization functions listed below.</p><pre>//Serialization code block<br>string data;<br>PERSON::Person proto_message; //PERSON package<br>proto_message.set_name(&quot;James Brown&quot;);<br>proto_message.set_id(7777000);<br>proto_message.set_email(&quot;james@brown.blog&quot;);<br>proto_message.SerializeToString(&amp;data); //string binary;<br>vector&lt;uint8_t&gt; binary_message(data.begin(), data.end());<br>cout &lt;&lt; &quot;The binary message size to send: &quot; &lt;&lt; proto_message.ByteSizeLong() &lt;&lt; &quot;bytes&quot; &lt;&lt; endl; <br>cout &lt;&lt; proto_message.Utf8DebugString() &lt;&lt; endl;<br>cout &lt;&lt; &quot;The serialized binary message: &quot; &lt;&lt; endl;<br>for (auto byte: binary_message) {<br>  cout &lt;&lt; hex &lt;&lt; setw(2) &lt;&lt; setfill(&#39;0&#39;) &lt;&lt; static_cast&lt;int&gt;(byte);<br>}</pre><pre>//Deserialization code block<br>char msg[1500]; //buffer to send and receive messages with<br>string binary = msg;<br>PERSON::Person p2; //PERSON package<br>p2.ParseFromString(binary);<br>cout &lt;&lt; &quot;Client: &quot; &lt;&lt; binary &lt;&lt; endl;<br>cout &lt;&lt; &quot;-&gt; &quot;;<br>cout &lt;&lt; &quot;[&quot;;<br>cout &lt;&lt; &quot;Name: &quot; &lt;&lt; p2.name() &lt;&lt; &quot; id: &quot; &lt;&lt; p2.id() &lt;&lt; &quot; Email: &quot; &lt;&lt; p2.email(); <br>cout &lt;&lt; &quot;]&quot; &lt;&lt; endl;</pre><p>To sum up, this serialization is equal for transmitting objects between programming languages using various transport methods like websocket, bluetooth, BLE, TCP, REST. Frankly, this interoperability assisted me a lot during my development experience in IoT domain where I had to interact with Web apps or embedded Software using iOS devices and Swift language.</p><p>In conclusion, this is the class that matches the proto file, that could be initialized as an object as soon as the message is unpacked and its data is assigned to the object’s properties.</p><pre>class Person {<br>  public:<br>    std::string name;<br>    int id;<br>    std::string email;<br>}</pre><p>Here are the full code snippets containing described modifications:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ee32ffb6517407b18817250e83cc8c48/href">https://medium.com/media/ee32ffb6517407b18817250e83cc8c48/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5ab7b8faeff5b47cc2988f687841c2dc/href">https://medium.com/media/5ab7b8faeff5b47cc2988f687841c2dc/href</a></iframe><p>Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8452b515c3e0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a simple weather app for iOS using Swift.]]></title>
            <link>https://alimovlex.medium.com/building-a-simple-weather-app-for-ios-using-swift-f3a24d8e1f22?source=rss-e5dff74a54de------2</link>
            <guid isPermaLink="false">https://medium.com/p/f3a24d8e1f22</guid>
            <category><![CDATA[rest-api]]></category>
            <category><![CDATA[apple]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[http-request]]></category>
            <category><![CDATA[client-server]]></category>
            <dc:creator><![CDATA[Аλέξιος]]></dc:creator>
            <pubDate>Wed, 15 Feb 2023 17:42:46 GMT</pubDate>
            <atom:updated>2023-02-15T17:48:08.656Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*EDWRoUeCmlNJoV1T.png" /><figcaption>Picture 1 — The weather icon by Apple.</figcaption></figure><p>Weather always plays an important role in our lives. Even logistics or business plans could be changed due to weather conditions. If you are curious about how weather apps work beneath the graphics level, I will be glad to elaborate on this topic and share the experience that I’ve gained. Let’s discover the internals of client-server applications.</p><h3>1. The fundamentals of HTTP requests.</h3><p>Let us start with the definition of HTTP. From the <a href="https://www.rfc-editor.org/rfc/rfc2616#:~:text=RFC%202616%3A%20Hypertext%20Transfer%20Protocol%20%2D%2D%20HTTP%2F1.1"><em>rfc2616</em></a><em> </em>document, the acronym HTTP stands for:</p><blockquote>The Hypertext Transfer Protocol (HTTP) is an application-level<br> protocol for distributed, collaborative, hypermedia information<br> systems. It is a generic, stateless, protocol which can be used for<br> many tasks beyond its use for hypertext, such as name servers and<br> distributed object management systems, through extension of its<br> request methods, error codes and headers.</blockquote><p>Hence, this protocol is widely used in web browsing and the modern version of it is called HTTPS where the letter “s” means secure. Besides, there are several kinds of HTTP requests that you can use to negotiate with the server’s backend using RESTful API. These requests are depicted in the following diagram below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/0*3VSm_BiscPr9ixaB.jpeg" /><figcaption>Picture 2— The HTTP request types diagram by <a href="https://medium.com/u/be624113079f">Ayush Verma</a>.</figcaption></figure><p>More information on this topic can be found in the article “<a href="https://javascript.plainenglish.io/http-request-methods-complete-guide-cced531a42b7"><em>HTTP Request Methods: A Complete Guide</em></a>” by <a href="https://ayushv.medium.com/">Aysh Verma</a>.</p><h3>2. The core principles of RESTful API.</h3><p>What is the meaning of the REST acronym? From the “<a href="https://www.redhat.com/en/topics/api/what-is-a-rest-api">Red Hat</a>” website the definition can be inferred below.</p><blockquote>A REST API (also known as RESTful API) is an application programming interface (API or web API) that conforms to the constraints of REST architectural style and allows for interaction with RESTful web services. REST stands for representational state transfer and was created by computer scientist Roy Fielding.</blockquote><p>Overall, it means the protocol of JSON file exchange via HTTP transport. The relevant diagram illustrating this process is attached below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*_D9-S4znkGWA7zcw.png" /><figcaption>Picture 3— The RESTful API diagram by adidoshi from <em>dev.to</em> website.</figcaption></figure><p>So, what is JSON? An explanation of it can be found on the official website <a href="https://www.json.org/json-en.html">json.org</a>.</p><blockquote><strong>JSON</strong> (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. It is based on a subset of the JavaScript Programming Language Standard ECMA-262 3rd Edition — December 1999. JSON is a text format that is completely language independent but uses conventions that are familiar to programmers of the C-family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others. These properties make JSON an ideal data-interchange language.</blockquote><p>Essentially, the JSON file that we will be parsing today has the subsequent image. This file was generated by the “<a href="https://openweathermap.org/current"><em>OpenWeatherMap</em></a><em>”</em> API.</p><pre>{<br>  &quot;coord&quot;: {<br>    &quot;lon&quot;: 7.4474,<br>    &quot;lat&quot;: 46.9481<br>  },<br>  &quot;weather&quot;: [<br>    {<br>      &quot;id&quot;: 800,<br>      &quot;main&quot;: &quot;Clear&quot;,<br>      &quot;description&quot;: &quot;clear sky&quot;,<br>      &quot;icon&quot;: &quot;01d&quot;<br>    }<br>  ],<br>  &quot;base&quot;: &quot;stations&quot;,<br>  &quot;main&quot;: {<br>    &quot;temp&quot;: 9.97,<br>    &quot;feels_like&quot;: 9.79,<br>    &quot;temp_min&quot;: 6.75,<br>    &quot;temp_max&quot;: 12.11,<br>    &quot;pressure&quot;: 1028,<br>    &quot;humidity&quot;: 41<br>  },<br>  &quot;visibility&quot;: 10000,<br>  &quot;wind&quot;: {<br>    &quot;speed&quot;: 1.34,<br>    &quot;deg&quot;: 220,<br>    &quot;gust&quot;: 1.34<br>  },<br>  &quot;clouds&quot;: {<br>    &quot;all&quot;: 5<br>  },<br>  &quot;dt&quot;: 1676476361,<br>  &quot;sys&quot;: {<br>    &quot;type&quot;: 2,<br>    &quot;id&quot;: 19940,<br>    &quot;country&quot;: &quot;CH&quot;,<br>    &quot;sunrise&quot;: 1676442936,<br>    &quot;sunset&quot;: 1676480002<br>  },<br>  &quot;timezone&quot;: 3600,<br>  &quot;id&quot;: 2661552,<br>  &quot;name&quot;: &quot;Bern&quot;,<br>  &quot;cod&quot;: 200<br>}</pre><p>Anyway, how to make an HTTP GET request and parse this incoming JSON file on iOS using Swift? Next is the guide on how to do it.</p><h3>3. Implementation of iOS weather app using Swift.</h3><p>Observing popular iOS frameworks I concluded with my choice of two well-known libraries <a href="https://github.com/Alamofire/Alamofire"><em>Alamofire</em></a> and <a href="https://github.com/SwiftyJSON/SwiftyJSON"><em>SwiftyJSON</em></a><em>. </em>They are documented and up-to-date nowadays, so even the neophyte could solve this simple task.</p><p>First of all, there is a reference to the URI formula of how to forge the HTTP GET request. Today, I chose Bern because frankly, I am zealous about Switzerland.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/644/1*ZQHtLqmfPo0j6O_7PEljNA.png" /><figcaption>Picture 4— The RESTful API documentation from the OpenWeatherMap website.</figcaption></figure><p>Therefore, our formed URI request formula looks like this:</p><blockquote><a href="https://api.openweathermap.org/data/2.5/weather?q=Bern&amp;appid=dd901d59fd590a54f070075a96812a94&amp;units=metric"><em>https://api.openweathermap.org/data/2.5/weather?q=Bern&amp;appid=dd901d59fd590a54f070075a96812a94&amp;units=metric</em></a></blockquote><p>Secondly, as the data on a web server will not be changed or modified the HTTP request has the GET type. The screenshot below from the documentation explains how to use the library’s method for it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SJSxmteue_5QmzFvOh5TFw.png" /><figcaption>Picture 4 — <a href="https://github.com/Alamofire/Alamofire/blob/master/Documentation/Alamofire%204.0%20Migration%20Guide.md">The screenshot from the documentation of the Alamofire iOS framework</a>.</figcaption></figure><p>Thirdly, the incoming JSON needs to be parsed by the SwiftyJSON framework to segregate the pertinent data from it. The screenshot below from the documentation also explains how to manage methods from it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/902/1*AW4_JZbWCbH9dWNxntK7bA.png" /><figcaption>Picture 5— The screenshot from the documentation of the SwiftyJSON iOS framework.</figcaption></figure><p>Ultimately, to make this straight, I attached the demo code displaying the steps to build the simple weather app on iOS. The expected output from the initialized object and the method used are below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bb14def53f9ff895a6c7b7f290ec967e/href">https://medium.com/media/bb14def53f9ff895a6c7b7f290ec967e/href</a></iframe><p>Expected output:</p><pre>{<br>    base = stations;<br>    clouds =     {<br>        all = 0;<br>    };<br>    cod = 200;<br>    coord =     {<br>        lat = &quot;46.9481&quot;;<br>        lon = &quot;7.4474&quot;;<br>    };<br>    dt = 1676482031;<br>    id = 2661552;<br>    main =     {<br>        &quot;feels_like&quot; = &quot;6.11&quot;;<br>        humidity = 49;<br>        pressure = 1029;<br>        temp = &quot;6.94&quot;;<br>        &quot;temp_max&quot; = &quot;9.08&quot;;<br>        &quot;temp_min&quot; = &quot;4.42&quot;;<br>    };<br>    name = Bern;<br>    sys =     {<br>        country = CH;<br>        id = 19940;<br>        sunrise = 1676442936;<br>        sunset = 1676480002;<br>        type = 2;<br>    };<br>    timezone = 3600;<br>    visibility = 10000;<br>    weather =     (<br>                {<br>            description = &quot;clear sky&quot;;<br>            icon = 01n;<br>            id = 800;<br>            main = Clear;<br>        }<br>    );<br>    wind =     {<br>        deg = 250;<br>        speed = &quot;1.54&quot;;<br>    };<br>}<br>The country name is: CH<br>The city name is: Bern<br>The sunrise is at: 2023-02-15 06:35:36 +0000<br>The sunset is at: 2023-02-15 16:53:22 +0000<br>The current temperature is: 7.0<br>The wind speed is: 2.0<br>The humidity is: 49.0<br>It feels like: 6.0<br>It is : Clear outside</pre><p>Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f3a24d8e1f22" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a simple BLE IoT app for iOS using Swift]]></title>
            <link>https://alimovlex.medium.com/building-a-simple-ble-iot-app-for-ios-using-swift-cb790039e375?source=rss-e5dff74a54de------2</link>
            <guid isPermaLink="false">https://medium.com/p/cb790039e375</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[bluetooth]]></category>
            <category><![CDATA[apple]]></category>
            <category><![CDATA[bluetooth-low-energy]]></category>
            <dc:creator><![CDATA[Аλέξιος]]></dc:creator>
            <pubDate>Sat, 15 Oct 2022 03:18:28 GMT</pubDate>
            <atom:updated>2022-10-15T11:32:45.005Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/512/0*s0fl8TyTWMCiijSE" /><figcaption>Picture 1 — The Bluetooth Auto Connect application logo by AwamiSolution.</figcaption></figure><p>In my previous article “<a href="https://alimovlex.medium.com/mastering-the-fundamentals-of-ble-in-ios-with-swift-73a43ffe44dc">Mastering the fundamentals of BLE for iOS using Swift</a>” I have already presented the core principles of BLE functionality but this time I am going to elucidate the internals of the BLE data transmission process.</p><p>Initially, let us remember the BLE data flow. The flow diagram is depicted below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/0*bCYJFoJbCz2AO3gP.jpg" /><figcaption>Picture 1 — The BLE connection procedure diagram.</figcaption></figure><p>Apparently, concerning reading the data from the peripheral, it is mandatory to define the following methods from the <em>“CBPeripheralDelegate”</em> protocol in your class:</p><p>Firstly, the peripheral has to provide the central manager with services available before initializing the channels of data transmission as it was described in my last article.</p><pre>func peripheral(_ <em>peripheral</em>: CBPeripheral, didDiscoverServices <em>error</em>: Error?)</pre><p>Secondly, the “didDiscoverCharacteristicsFor <em>service” </em>method is the inception of the data exchange process via BLE protocol. Similarly, the BLE characteristics are the endpoints in networking terms through which the packets are sent (Wi-Fi or Ethernet) that have their unique identifiers known as UUID.</p><pre>func peripheral(_ <em>peripheral</em>: CBPeripheral, didDiscoverCharacteristicsFor <em>service</em>: CBService, <em>error</em>: Error?)</pre><p>Thirdly, as soon as the desired characteristic is selected, the central manager subscribes to the peripheral’s characteristics notifications that have the payload.</p><pre>func peripheral(_ <em>peripheral</em>: CBPeripheral, didUpdateNotificationStateFor <em>characteristic</em>: CBCharacteristic, <em>error</em>: Error?)</pre><p>Besides, if the peripheral transmits binary data, the <em>“didUpdateValueFor characteristic” </em>method is called where the contents of the incoming parcel can be investigated.</p><pre>public func peripheral(_ <em>peripheral</em>: CBPeripheral, didUpdateValueFor <em>characteristic</em>: CBCharacteristic, <em>error</em>: Error?)</pre><p>By the way, when the data from the central manager has been sent, the “<em>didWriteValueFor characteristic</em>” is invoked where the contents of the outcoming parcel can be examined.</p><pre>func peripheral(_ <em>peripheral</em>: CBPeripheral, didWriteValueFor <em>characteristic</em>: CBCharacteristic, <em>error</em>: Error?)</pre><p>To sum up, the algorithm of a BLE connection consists of two essential things:</p><ol><li>Adjusting the methods for the central manager from the “<em>CBCentralManagerDelegate”</em> protocol.</li><li>Configuring the methods for the peripheral from the “<em>CBPeripheralDelegate” </em>protocol.</li></ol><p>Ultimately, to make this candid, I attached the demo code displaying the steps to access the BLE protocol on iOS.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/26d11f9a2a973699f7ab43923fc3cc46/href">https://medium.com/media/26d11f9a2a973699f7ab43923fc3cc46/href</a></iframe><p>Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cb790039e375" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a simple TCP chat for iOS using Swift.]]></title>
            <link>https://alimovlex.medium.com/building-a-simple-tcp-chat-in-ios-using-swift-ff8da446543?source=rss-e5dff74a54de------2</link>
            <guid isPermaLink="false">https://medium.com/p/ff8da446543</guid>
            <category><![CDATA[internet]]></category>
            <category><![CDATA[apple]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[tcp]]></category>
            <dc:creator><![CDATA[Аλέξιος]]></dc:creator>
            <pubDate>Sun, 09 Jan 2022 16:59:29 GMT</pubDate>
            <atom:updated>2023-11-25T20:17:58.634Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/620/0*OHllq1OZsIVb5G4Q.jpg" /><figcaption>Picture 1 — The iMessage icon by Apple.</figcaption></figure><p>Last month, I was assigned the task that involved the chat application implementation for iOS on a commercial project using raw TCP sockets. I hesitated because I was a neophyte in sockets programming. Although I had this conundrum and convoluted assignment, I have completed it! Besides, the TCP internals sounds more candid for me now than before, so I will be grateful to share my knowledge about it here.</p><p>Let us start with the definition of TCP. From the <a href="https://datatracker.ietf.org/doc/html/rfc793"><em>rfc793</em></a><em> </em>document the acronym TCP stands for:</p><pre>The Transmission Control Protocol (TCP) is intended for use as a highly reliable host-to-host protocol between hosts in packet-switched computer communication networks, and in interconnected systems of such networks.</pre><p>Therefore, it can be used as a reliable alternative for UDP (User Datagram Protocol) because of the three-way handshake way of connection establishment as it is depicted on the diagram below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*DpMDonUIxmxlXPyvAdPP9Q.png" /><figcaption>Picture 2— The TCP three-way handshake connection diagram.</figcaption></figure><p>Hence, there are the core principles of the TCP explained down here.</p><h3>1. The fundamentals of TCP connection.</h3><p>In fact, a three-way handshake is a method used in a TCP/IP network to create a client-server connection that requires both the client and the server to exchange SYN (synchronization) and ACK (acknowledgment) packets before the actual data transmission starts.</p><p>Here is the algorithm of the TCP three-way handshake:</p><ul><li>At first, the client sends the SYN data packet via an IP network to the server. The purpose of this packet is to ask or infer if the server is open for new connections.</li><li>Secondly, the addressed server has to contain opened ports for inbound connections initialization. As soon as the server receives the SYN packet from the client node, it responds and returns a confirmation — the ACK packet or SYN/ACK packet.</li><li>In the end, the client node receives the SYN/ACK from the server and responds with an ACK packet.</li></ul><p>Thus, the theory part is over. Let us dive into implementation!</p><h3>2. The TCP reference from the Foundation library.</h3><p>Initially, the mandatory methods from the Foundation library have to be imported into the project for TCP connection functions management.</p><p>As the “<a href="https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Streams/Streams.html#:~:text=A%20stream%20is%20a%20fundamental,NSStream%2C%20NSInputStream%2C%20and%20NSOutputStream."><em>Stream Programming Guide for Cocoa</em></a>” states:</p><pre>A stream is a fundamental abstraction in programming: a sequence of bits transmitted serially from one point to another point. Cocoa provides three classes to represent streams and facilitate their use in your programs: NSStream, NSInputStream, and NSOutputStream. With the instances of these classes you can read data from, and write data to, files and application memory. You can also use these objects in socket-based connections to exchange data with remote hosts. You can also subclass the stream classes to obtain specialized stream behavior.</pre><p>Consequently, here is the scheme of sockets connection using Apple’s Foundation library for better comprehension.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-58bSt_4J4SEO2icEWu25g.jpeg" /><figcaption>Picture 3— The sockets’ communication diagram from the “Stream Programming Guide for Cocoa”.</figcaption></figure><h3>3. The TCP connection implementation in iOS using Swift.</h3><p>In fact, in order to initiate the TCP connection, the designated class has to conform to the “<em>StreamDelegate” </em>protocol and needs to inherit the “<em>NSObject”</em> class. Furthermore, it is compulsory to define properties such as read/write and input/output streams as it is written below.</p><pre>var readStream: Unmanaged&lt;CFReadStream&gt;?    <br>var writeStream: Unmanaged&lt;CFWriteStream&gt;?    <br>var inputStream: InputStream?    <br>var outputStream: OutputStream?</pre><p>Optionally, the URL server address and port could be defined in the class initializer as stated in this part of the code.</p><pre>private var url: URL;    <br>private var port: UInt32;     </pre><pre>init(url: URL, port: UInt32) <br>{        <br>self.url = url;        <br>self.port = port;    <br>}</pre><p>In addition, there are several steps to start the TCP connection to the server.</p><ul><li>Firstly, you have to call the <em>“CFStreamCreatePairWithSocketToHost” </em>for server-client binding.</li></ul><pre>CFStreamCreatePairWithSocketToHost(kCFAllocatorDefault, (url.absoluteString as CFString), port, &amp;readStream, &amp;writeStream);</pre><ul><li>Secondly, the input and output streams have to be initialized and their delegates should be assigned to self for proper functioning.</li></ul><pre>outputStream = writeStream?.takeRetainedValue()        <br>inputStream = readStream?.takeRetainedValue()        outputStream?.delegate = self;        <br>inputStream?.delegate = self;</pre><ul><li>Thirdly, it is mandatory for streams to be scheduled for receiving stream events on a run loop. By doing this, the delegate evades being blocked when there is no data on the stream to read. If streaming is taking place on another thread, be sure to schedule the stream object on that thread’s run loop. You should never attempt to access a scheduled stream from a thread different than the one owning the stream’s run loop.</li></ul><pre>outputStream?.schedule(in: RunLoop.current, forMode: RunLoop.Mode.default);        <br>inputStream?.schedule(in: RunLoop.current, forMode: RunLoop.Mode.default);</pre><ul><li>Finally, you are ready to open the streams’ session via these lines of code.</li></ul><pre>outputStream?.open();        <br>inputStream?.open();</pre><ul><li>Moreover, the <em>“StreamDelegate” protocol </em>contains the method for handling stream events and it serves as a stream condition tracker.</li></ul><pre>func stream(_ aStream: Stream, handle eventCode: Stream.Event)</pre><p>After a stream object is sent open, you can find out about its status, whether it has bytes available to read, and the nature of any error with the following messages:</p><ul><li>streamStatus</li><li>hasBytesAvailable</li><li>streamError</li></ul><p>The returned status is a StreamStatus constant indicating that the stream is opening, reading, at the end of the stream, and so on.</p><p>Lastly, there is the send method for messages transmission over raw TCP sockets to the server.</p><pre>func send(message: String){         <br>let response = &quot;msg:\(message)&quot;        <br>let buff = [UInt8](message.utf8)        <br>if let _ = response.data(using: .ascii) {            outputStream?.write(buff, maxLength: buff.count)        <br>}</pre><p>Ultimately, there is the algorithm from “<a href="https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Streams/Articles/ReadingInputStreams.html#//apple_ref/doc/uid/20002273-BCIJHAGD"><em>Stream Programming Guide for Cocoa</em></a>” for recapitulation of all TCP information written above and the demo picture with code attached illustrating the TCP chat created between the iOS application and the <em>“</em><a href="https://packetsender.com/"><em>Packet Sender</em></a><em>” </em>Software.</p><p>In Cocoa, reading from an InputStream instance consists of several steps:</p><ol><li><a href="https://medium.com/General/Conceptual/DevPedia-CocoaCore/ObjectCreation.html#//apple_ref/doc/uid/TP40008195-CH39">Create and initialize</a> an instance of InputStream from a source of data.</li><li>Schedule the stream object on a run loop and open the stream.</li><li>Handle the events that the stream object reports to its delegate.</li><li>When there is no more data to read, <a href="https://medium.com/General/Conceptual/DevPedia-CocoaCore/MemoryManagement.html#//apple_ref/doc/uid/TP40008195-CH27">dispose</a> of the stream object.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1017/1*5NeM4ZvlXZusTEbYJscr2w.gif" /><figcaption>Picture 4— The iOS chat application test using “Packet Sender” by <a href="https://github.com/anoop4real/SocketSwiftSample">anoop4real</a>.</figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b250decabece38d7cf46e6b6f8340a50/href">https://medium.com/media/b250decabece38d7cf46e6b6f8340a50/href</a></iframe><p>Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ff8da446543" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering the fundamentals of CoreLocation for iOS using Swift.]]></title>
            <link>https://alimovlex.medium.com/mastering-the-fundamentals-of-corelocation-in-ios-with-swift-1d84083eac4a?source=rss-e5dff74a54de------2</link>
            <guid isPermaLink="false">https://medium.com/p/1d84083eac4a</guid>
            <category><![CDATA[gps]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[maps]]></category>
            <category><![CDATA[apple]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Аλέξιος]]></dc:creator>
            <pubDate>Sun, 03 Oct 2021 13:16:04 GMT</pubDate>
            <atom:updated>2022-01-10T21:17:21.593Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/512/0*ybeeuIe4ByV7Y276.jpg" /><figcaption>Picture 1 — The Apple Maps application logo.</figcaption></figure><p>Nowadays, it is impossible to be lost in an enormous city as people often use GPS in their smartphones because it is so simple and convenient to open the required application rather than looking for a place on the printed map.</p><p>Perhaps, this geopositioning system kindled the interest of how it might be devised inside. So, here I am going to elucidate the pith of CoreLocation internals from the perspectives of iOS and using the Swift programming language.</p><p>Generally speaking, the CoreLocation is the none-UI way of determining the location where the basic object is <em>“CLLocation”, </em>consisting of properties like:</p><ol><li>Coordinate</li><li>Altitude</li><li>Horizontal and vertical accuracy</li><li>Timestamp</li><li>Speed</li><li>Course</li></ol><p>By the way, the <em>“kCLLocationAccuracy“ </em>property has six states for handling location such as:</p><ol><li>Best for Navigation.</li><li>AccuracyBest</li><li>NearestTenMeters</li><li>HundredMeters</li><li>Kilometer</li><li>ThreeKilometers</li></ol><p>Irrefutably, <strong><em>the more accuracy you request, the more battery will be used for location tracking.</em></strong> There are three ways of detecting the location, for example:</p><ul><li>Using cellular tower triangulation (not precise, but low powered)</li><li>Wi-Fi node database lookup (more accurate, more power)</li><li>GPS (precise, power consumptive)</li></ul><p>To track the location coordinates, you have to do the following steps:</p><ul><li>Firstly, import the CoreLocation framework to use the mandatory functions for GPS module initialization. Additionally, define the class with the name conforming to the <strong><em>“</em></strong><em>CLLocationManagerDelegate” </em>protocol and inherit the <em>“NSObject” </em>class.</li><li>Secondly, assign the variables to the location manager and to the current location where will be stored latitude and longitude.</li></ul><pre>let locationManager = CLLocationManager()    <br>var currentLocation: CLLocation!</pre><ul><li>Thirdly, set the location manager delegate to self and define the location manager&#39;s behavior, if it has the desired location accuracy as it is written below in the class initializer. As for me, I prefer the best location precision.</li></ul><pre>override init() {<br>super.init();<br>self.locationManager.delegate = self;<br>self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;<br>}</pre><ul><li>Also, it is compulsory to ask the user whether he wants to use the location and to display the explanatory message.</li></ul><p>There are two methods available, such as <em>“requestWhenInUseAuthorization”</em> and “requestAlwaysAuthorization”. Unless authorization is granted by the user, the application’s GPS authorizationStatus will be “<em>NotDetermined”</em>.</p><pre>locationManager.requestWhenInUseAuthorization()</pre><p>Moreover, add your GPS request message to the <strong><em>Info.plist </em></strong>file here:</p><pre>Privacy - Location Always and When in use usage description</pre><p>Here is the message below that will be displayed during the first application launch requesting permission to the location access if the <em>“locationAuthStatus” </em>method is called. Then, your location coordinates will be gained via GPS, cell tower, or Wi-Fi and printed in the terminal XCode window.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/658/0*1Ai9TG5SwHTxbk-K.png" /><figcaption>Picture 2— The iOS location permission request message.</figcaption></figure><p>Ultimately, to make this candid, I attached the demo code displaying the steps to access the CoreLocation on iOS.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/93354709c823c51b7a3a645b1bcec099/href">https://medium.com/media/93354709c823c51b7a3a645b1bcec099/href</a></iframe><p>Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1d84083eac4a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering the fundamentals of BLE for iOS using Swift.]]></title>
            <link>https://alimovlex.medium.com/mastering-the-fundamentals-of-ble-in-ios-with-swift-73a43ffe44dc?source=rss-e5dff74a54de------2</link>
            <guid isPermaLink="false">https://medium.com/p/73a43ffe44dc</guid>
            <category><![CDATA[apple]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[bluetooth]]></category>
            <category><![CDATA[bluetooth-low-energy]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Аλέξιος]]></dc:creator>
            <pubDate>Sun, 12 Sep 2021 06:58:05 GMT</pubDate>
            <atom:updated>2022-10-15T01:21:35.085Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*sN5m2p-4LLdYo_5x.jpg" /><figcaption>Picture 1— The BLE connection diagram by <em>Martin Shellaker, director at SMP</em>.</figcaption></figure><p>From the first impression of working with BLE (Bluetooth Low Energy), I was surprised by how the event-based buses work. By the way, from my experience in Embedded Software Development, I was a neophyte and circumvented the convoluted challenging tasks that were arduous and arcane for me.</p><p>Nevertheless, that day has come and now I am going to elucidate the pith of BLE internals from the perspectives of iOS and using the Swift programming language.</p><p>First of all, here is the reference diagram for the BLE functioning logic.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vlSVunU7mvFMg-b0.jpeg" /><figcaption>Picture 2 — The BLE connection workflow diagram by <a href="http://twitter.com/amin030296">@amin030296</a>.</figcaption></figure><p>Here are the hints for each step of the BLE connection to clarify this scheme that makes it more candid.</p><ul><li>Firstly, the Bluetooth connection always begins with initialization when the user permits the connection during the application launch. So, if the peripheral is enabled for discovery, then it sends the broadcasting packets to the phone for identification. [1]</li><li>Secondly, when the advertisement packet is received by phone from the source, the Bluetooth manager stops scanning and attempts to connect to the sender. [2]</li><li>Thirdly, if the binding between the mobile device and peripheral is successful, the phone continues discovering available services on peripheral while the peripheral halts sending advertisement packets on connection and then provides the information about the accessible services. [3]</li><li>Next, the central manager requests the peripheral for the additional characteristics, while the peripheral responds with further information.[4]</li><li>Ultimately, the BLE connection between two gadgets is established! Now, let us see how to implement this in Xcode!</li></ul><p>At first, it is mandatory to import the CoreBluetooth framework to use the mandatory functions for establishing BLE connections. Additionally, define the class with the name conforming to <strong><em>“</em></strong><em>CBCentralManagerDelegate” </em>and “<em>CBPeripheralDelegate” </em>protocols.</p><p>Also, write the description of the peripheral’s UUID service which was received from broadcasting packets. By the way, assign the variables to the central Bluetooth manager and peripheral matching their types.</p><pre>let DEVICE_SERVICE_UUID = CBUUID.init(string: &quot;b4250400-fb4b-4746-b2b0-93f0e61122c6&quot;); //the peripheral&#39;s UUID</pre><pre>var centralManager: CBCentralManager!;    <br>var peripheral: CBPeripheral!;</pre><p>Besides, the <strong><em>“</em></strong><em>CBCentralManagerDelegate” </em>requires only one method for handling updates occurring on the phone’s Bluetooth central manager, if the user grants access to the application during its startup or in the iOS settings for exploring the BLE peripherals with specified UUID. This is the first step [1] from the BLE connection procedure diagram description.</p><pre>func centralManagerDidUpdateState(_ central: CBCentralManager)</pre><p>Furthermore, if the phone locates the BLE device, the <em>“didDiscover peripheral” </em>method will manage the future events on discovery. It usually happens when the iOS gadget collects the advertisement package from the peripheral. This is step two [2] from the BLE connection procedure diagram description.</p><pre>func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber)</pre><p>Consequently, if the central manager establishes the connection with the BLE peripheral, it looks for additional services available on the peripheral. The <em>“didConnect peripheral” </em>method will take care of future events regarding the network state. This is step three [3] from the BLE connection procedure diagram description.</p><pre>func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral)</pre><p>In addition, you can track the earlier defined peripheral’s UUID and check, if it matches the DEVICE_SERVICE_UUID variable using the <em>“didDiscoverServices peripheral” </em>method. So, if it contains a similar UUID, the connection between devices could be established. Otherwise, the warning might be printed for debugging purposes. This is step four [4] from the BLE connection procedure diagram description.</p><pre>func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: Error?)</pre><p>Finally, if the device suddenly disconnects, there is the <em>“didDisconnectPeripheral” </em>method for organizing the following events regarding your iOS project intentions.</p><pre>func centralManager(_ central: CBCentralManager, didDisconnectPeripheral peripheral: CBPeripheral, error: Error?)</pre><p>Ultimately, here is the flow chart of how the BLE connection is organized for making it straightforward and the demo code attached for description.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/730/0*zLYe_VbeFAUvMOVh.jpg" /><figcaption>Picture 3— The BLE connection flow chart by freecodecamp.org website.</figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/61534d9ca0324d33b30e2e6353e4d328/href">https://medium.com/media/61534d9ca0324d33b30e2e6353e4d328/href</a></iframe><p>P.S. Add your Bluetooth request message to the <strong><em>Info.plist </em></strong>file here:</p><pre>Privacy - Bluetooth Always Usage Description</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/506/0*_Q0QA82IAb37Z1GG.png" /><figcaption>Picture 3 — iOS Bluetooth permission request message.</figcaption></figure><p>Now, you are ready to call the <em>“connect()”</em> method for establishing the BLE connection with the peripheral where the central manager delegate will be set and initialized via this line of code:</p><pre>centralManager = CBCentralManager(delegate: self, queue: .global());</pre><p>Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=73a43ffe44dc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Linking the C/C++ code with Swift]]></title>
            <link>https://alimovlex.medium.com/linking-the-c-code-with-swift-1c18f6316962?source=rss-e5dff74a54de------2</link>
            <guid isPermaLink="false">https://medium.com/p/1c18f6316962</guid>
            <category><![CDATA[apple]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[cplusplus]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Аλέξιος]]></dc:creator>
            <pubDate>Sat, 12 Jun 2021 06:15:44 GMT</pubDate>
            <atom:updated>2021-09-11T09:22:01.894Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1KeMuo0YFIIz8iGa8mtOhA.jpeg" /><figcaption>Picture 1 — the programming languages logotypes.</figcaption></figure><p>From my first impression, I saw how Swift is similar to C/C++ which I used before during my occupation in Embedded Software Engineering. Therefore, imminently, I came up with the invigorating idea of aggregating my Sandboxes where I tested my code.</p><p>Additionally, I had already learned that Swift supports Objective-C code via the bridging header by default when I built iOS tutorial projects. Then, I discovered that the C++ code could be linked as the C code via the <strong>“extern “C”</strong> keyword. So, let us look at what it takes to compile the program written in Swift and C++.</p><p>Firstly, you need to put your C++ files into a separate folder where you have to store your public functions from the library. Here is the project’s structure.</p><pre>Sources                  <br>    SwiftCPP              LibraryCPP <br>    main.swift            include <br>                             sandbox.hpp         <br>                          sandbox.cpp</pre><p>For reference:</p><blockquote>The <strong><em>“Sources”</em></strong> folder includes two folder named SwiftCPP and LibraryCPP.</blockquote><blockquote>Beneath<strong><em> “SwiftCPP”</em></strong> there is the main.swift file where you can call the public C functions from your library.</blockquote><blockquote>The “<strong><em>LibraryCPP”</em></strong> folder is located at the same level as SwiftCPP and it contains the include directory where the “<strong><em>sandbox.hpp”</em></strong> public header is stored.</blockquote><blockquote>The “<strong><em>sandbox.cpp”</em></strong> source file is placed on the similar level as the include folder below LibraryCPP</blockquote><p>Secondly, add to your header file the<strong> extern “C” </strong>and conditional compilation instructions with functions’ signatures like this below.</p><pre>//This is the sandbox.hpp</pre><pre>#ifdef __cplusplus<br><strong>extern </strong>&quot;C&quot; {<br>#endif<br><strong>int </strong>sandbox();<br>#ifdef __cplusplus<br>}<br>#endif</pre><p>Thirdly, do not forget to create the body of the functions that you are going to use in your project. Here is an example of a simple function.</p><pre>//This is the sandbox.cpp</pre><pre>#include &quot;include/sandbox.hpp&quot;<br>#include &lt;iostream&gt;</pre><pre><strong>using namespace </strong>std;</pre><pre><strong>int </strong>sandbox() {<br>    cout&lt;&lt;&quot;Hello from C++!&quot;&lt;&lt;endl;<br>    <strong>return </strong>0;<br>}</pre><p>Furthermore, to use your C++ code, you have to define your library in the Packages.swift</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3a9d826501e16b79026b37c2e9965527/href">https://medium.com/media/3a9d826501e16b79026b37c2e9965527/href</a></iframe><p>Finally, you can now import your C++ library and call the public functions which you have already defined in the “<strong><em>sandbox.hpp”</em></strong> header.</p><pre><strong>import </strong>LibraryCPP<br><br>print(&quot;The C++ function exit status is = \( sandbox())&quot;);</pre><p>Here is the quick recapitulation of how to bind the C++ code with Swift:</p><ul><li>Firstly, create a specific folder for the source files.</li><li>Secondly, paste your header into the include folder</li><li>Next, define your library in Swift’s package linker.</li><li>Don’t forget to import your library in the swift executable’s source.</li><li>Ultimately, you can call your public methods from the swift’s source files.</li></ul><p>Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1c18f6316962" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Making CoreData compatible with iOS 9 and 10+ simultaneously.]]></title>
            <link>https://alimovlex.medium.com/how-to-make-coredata-compatible-with-ios-9-and-ios-10-or-later-simultaneously-e4cad79533cb?source=rss-e5dff74a54de------2</link>
            <guid isPermaLink="false">https://medium.com/p/e4cad79533cb</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[core-data]]></category>
            <category><![CDATA[apple]]></category>
            <dc:creator><![CDATA[Аλέξιος]]></dc:creator>
            <pubDate>Thu, 06 May 2021 08:04:11 GMT</pubDate>
            <atom:updated>2021-09-12T05:10:58.435Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*FTDvJ9exz5Wve1a2jYFBiw.png" /><figcaption>Picture 1 — The “Hello CoreData!” picture from stfalcon company’s website.</figcaption></figure><p>While I was exploring tutorials of iOS 11, I tried to make a universal CoreData database both for my iPhone 4S and iPhone 5S. Finally, I came to the conclusion that works fine stable, and properly as expected. So, here I am going to elucidate the steps of how to support the old iOS 9 and modern iPhone/iPad applications.</p><p>Firstly, add CoreData to your project. You can do this while creating a new one. Just check the box in front of the “Use Core Data” section.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/402/1*227nrrd75pjiCDCQS1Qdyg.png" /><figcaption>Picture 2— The new project creation in Xcode.</figcaption></figure><p>After, you have to edit your CoreData stack code in the “<em>AppDelegate.swift”</em> file. Here is the modified code you should paste in the CoreData stack section.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a16afd44315315601fde3dfd02180ef0/href">https://medium.com/media/a16afd44315315601fde3dfd02180ef0/href</a></iframe><p>Don’t forget to change the String values listed below as “goalpost” to your database model.</p><pre>let container = NSPersistentContainer(name: “goalpost”)</pre><pre>let modelURL = Bundle.main.url(/service/forresource: %E2%80%9Cgoalpost%E2%80%9D, withExtension: %E2%80%9Cmomd%E2%80%9D)!</pre><pre>let url = self.applicationDocumentsDirectory.appendingPathComponent(“goalpost.sqlite”)</pre><p>Ultimately, the whole demo project you can download on my github page where I tested both approaches and they worked perfectly on iPhone 4S running iOS 9.3.6 and on iPhone 5S with iOS 12.5.3 installed.</p><p>Happy coding!</p><p><a href="https://github.com/alimovlex/DevSlopes/tree/master/iOS%2011/goalpost-app">alimovlex/DevSlopes</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e4cad79533cb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Shifting to Linux and macOS from Windows]]></title>
            <link>https://alimovlex.medium.com/how-i-chose-linux-and-macos-over-windows-bef4593dfed8?source=rss-e5dff74a54de------2</link>
            <guid isPermaLink="false">https://medium.com/p/bef4593dfed8</guid>
            <category><![CDATA[windows]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[software]]></category>
            <category><![CDATA[macos]]></category>
            <dc:creator><![CDATA[Аλέξιος]]></dc:creator>
            <pubDate>Tue, 04 May 2021 10:18:06 GMT</pubDate>
            <atom:updated>2021-07-03T02:33:15.812Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MwBeWXnHBdYR_dzzD_FTMw.jpeg" /><figcaption>The image from “Linux vs Mac vs Windows” article is located on geekbot website.</figcaption></figure><p>It has been two years since I used Windows as the main operating system on my laptop where I did everything is connected to my job. Even now, I am fully satisfied with running Linux and macOS on my laptop and here I am going to posit the reasons for this selection.</p><p>Firstly, I read about Linux in the book of how to be a white hacker which described the internals of the world wide web. Initially, I tried to install the FreeBSD distro and was discouraged because I was a neophyte when started to explore the default preinstalled software due to the ambiguous ideas of its application to my projects. Hence, I decided to stay on Windows longer.</p><p>Secondly, I heard Linux name for the second time during my job experience as Embedded Software Tester in the automotive project and when I was interviewed for the microcontroller programmer’s position. As I was taught at University to develop firmware in Keil Uvision Windows’ IDE, building and flashing the binary files into the arm-based controllers on Linux was a conundrum for me. Therefore, I was fledgling and hesitating when the prospective employers asked me about the Unix architecture or the constituent shell commands.</p><p>As the result, I began reading vigorously guides, tutorials, and books about Linux administration to endeavor the intermediate knowledge of its fundamentals where I could extend my skills in Software Engineering. By the way, the compiler’s contents seemed less equivocal for me while I was reading the programmings’ guides such as preprocessing, compilation, assembling, and linking. So, configuring new development environments was finally as simple for me as using the terminal quotidianly. This is how I opened the way of devising Embedded Software on Linux.</p><p>Then, a few months later I was in the destitute of elementary drawing applications like Paint on Windows. I strived to use complex programs like GIMP on Linux but I did not succeed in making the chart for my mundane activities. Also, I came up with the idea to try macOS with its recommended Pixelmator Pro app and included Xcode for iOS development. Consequently, these two factors galvanized me to defer using Windows for my daily tasks and kindled the motivation to stick to the Unix environment instead of Windows.</p><p>To sum up, I am listing the aspects of why I switched to Linux and macOS.</p><ol><li>The essential software and utilities for ordinary tasks are bundled from the fresh start. For instance, multimedia, development tools, necessary drivers, editors, and office apps are already installed from the first launch!</li><li>It is rather more rapid to enter the command into the shell rather than looking for a needed button to accomplish the desired functionality.</li><li>There are no worries about malware on Unix-based operating systems as it is usually written for Windows.</li></ol><p>In the end, if you are a freelancer, software developer/tester, or journalist, there is no doubt, why should not you try Linux or macOS in serving your daily computing demands smoothly.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bef4593dfed8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Switching from C++ to Swift.]]></title>
            <link>https://alimovlex.medium.com/switching-from-c-to-swift-3920f3494e9b?source=rss-e5dff74a54de------2</link>
            <guid isPermaLink="false">https://medium.com/p/3920f3494e9b</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[cplusplus]]></category>
            <category><![CDATA[embedded-systems]]></category>
            <category><![CDATA[apple]]></category>
            <dc:creator><![CDATA[Аλέξιος]]></dc:creator>
            <pubDate>Sat, 01 May 2021 22:23:48 GMT</pubDate>
            <atom:updated>2022-01-16T07:38:47.862Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*IiaRwtL7p-xI5XTAVSGLrg.jpeg" /><figcaption>The Algoworks’ image on language performance from “Shift to SWIFT: An Unusual Journey from Objective-C”.</figcaption></figure><p>A few months ago I decided to explore Apple’s ecosystem from the developer’s point of view and I was surprised how similar is C++ to Swift is. But before that, I had experience with Embedded Software testing in Automotive projects and in making tutorial projects in C++ using Linux that bolstered me to learn the three inviolate principles of object-oriented programming by heart and made me curious about the internals of macOS and iOS.</p><p>Initially, I began discovering the Objective-C programming language and installed its compiler on Linux via the terminal command:</p><pre>sudo apt-get –y install gobjc gnustep gnustep-devel</pre><p>From the first look, this language has similarities with the C language and contains some extensions to it like OOP methods and classes. I thought that would be a great idea to try it before catching the recondite design paradigms of C++. Overall, it worked out! I stopped hesitating on job interviews and finally — felt confident about sacrosanct C++ philosophy. Besides, I got the pith of Standard Template Library which contained data structures with algorithms on its maintenance.</p><p>By the way, my second step in researching iOS was my draft application on my iPhone where I tried to bind the Objective-C code to C++. Surprisingly, I have found the bridging solution which I tried on my example of a blank Twitter application from “<em>Head First iPhone and IPad Development: A Learner’s Guide to Creating Objective-C Applications for the iPhone and IPad</em>”. Here is the solution which I have found on GitHub.</p><ol><li>Create the definition of a pointer to the class which is written in C++ in your ViewController header.</li></ol><pre>#import &lt;UIKit/UIKit.h&gt;</pre><pre><strong>@interface</strong> InstaTwitViewController : UIViewController</pre><pre>{</pre><pre><strong>struct</strong> CPPMembers *_cppMembers;</pre><pre>}</pre><pre>- (<strong>IBAction</strong>)tweetButtonTapped:(<strong>id</strong>)sender;</pre><pre><strong>@end</strong></pre><p>2. Outline its body in your ViewController implementation and place it after the headers import section. Do not forget to include the C++ header which contains your class.</p><pre>#import &quot;InstaTwitViewController.h&quot;<br>#import &quot;somecppfile.hpp&quot;</pre><pre><strong>struct</strong> CPPMembers</pre><pre>{</pre><pre>   CPPClass member1; //the CPPClass in somecppfile.hpp header</pre><pre>};</pre><p>3. Describe the class, its properties, bodies, and methods.</p><pre>#include &lt;cstdio&gt;<br>#include &lt;cstdlib&gt;<br>#include &lt;iostream&gt;<br>#include &lt;string&gt;</pre><pre><strong>using</strong> <strong>namespace</strong> std;</pre><pre><strong>class</strong> CPPClass</pre><pre>{</pre><pre><strong>public</strong>:</pre><pre>string foo()<br>{</pre><pre>   return &quot;Hello world!&quot;;<br>}</pre><pre>};</pre><p>4. Finally, create an instance of the object and call this method in your ViewController implementation section. Also, rename your *.m files to *.mm.</p><pre><strong>@implementation</strong> InstaTwitViewController</pre><pre>- (<strong>void</strong>)viewDidLoad {</pre><pre>[<strong>super</strong> viewDidLoad];</pre><pre>}</pre><pre>- (<strong>IBAction</strong>)tweetButtonTapped:(<strong>id</strong>)sender {</pre><pre>_cppMembers = new CPPMembers; </pre><pre>NSString *msg = [NSString stringWithFormat:@&quot;%s&quot;, <br>_cppMembers-&gt;member1.foo().c_str()];</pre><pre>NSLog(@&quot;%@&quot;, msg);</pre><pre>}</pre><p>5. To prevent memory leaks — deallocate your C++ object from the heap.</p><pre>- (<strong>void</strong>)dealloc</pre><pre>{</pre><pre>delete _cppMembers;</pre><pre>}</pre><pre>@end</pre><p>For a moment, I had a belief that — writing C++ applications for iOS is an excellent idea! But here are a few moments that prevented me to do this:</p><ul><li>The complexity of the process.</li><li>Swift is a way simpler solution for building apps than Objective-C++.</li></ul><p>Additionally, Swift is Apple’s replacement for the old Objective-C syntax which is recommended nowadays. There are myriad external libraries and Frameworks in Cocoapods written in Swift comparably to Objective-C. Let us take a look at similar syntax but in Swift:</p><ol><li>Model file.</li></ol><pre><strong>import</strong> Foundation</pre><pre><strong>class</strong> Blank {</pre><pre><strong>func</strong> foo()</pre><pre>{</pre><pre>print(&quot;Hello World!&quot;)</pre><pre>}</pre><pre>}</pre><p>2. Controller file with connected IBAction button action.</p><pre><strong>import</strong> UIKit</pre><pre><strong>class</strong> ViewController: UIViewController {</pre><pre><strong>override</strong> <strong>func</strong> viewDidLoad() {</pre><pre><strong>super</strong>.viewDidLoad()</pre><pre>// Do any additional setup after loading the view.</pre><pre>}</pre><pre><strong>@IBAction</strong> <strong>func</strong> tweetButtonTapped(<strong>_</strong> sender: <strong>Any</strong>) {</pre><pre><strong>let</strong> sandbox = Blank();</pre><pre>sandbox.foo();</pre><pre>}</pre><pre>}</pre><p>Is not that easy as it seems? In my view, it is! Conspicuously, There are two steps instead of five. In the end, I am happy going with Swift than with Objective-C++ and sticking to Apple’s technologies!</p><p>Ultimately, if you have some experience with C/C++ or with Embedded systems and want to switch to mobile applications development, I advise you to go with iOS. Swift is the intelligible language for beginners and some pre-intermediate coders with little experience.</p><p>Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3920f3494e9b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>