<?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 Rodrigo Freitas on Medium]]></title>
        <description><![CDATA[Stories by Rodrigo Freitas on Medium]]></description>
        <link>https://medium.com/@rodrigo_freitas?source=rss-b2543559991c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*F07XEVZZ-70UQeH_q_iFDw.jpeg</url>
            <title>Stories by Rodrigo Freitas on Medium</title>
            <link>https://medium.com/@rodrigo_freitas?source=rss-b2543559991c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 21:18:34 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rodrigo_freitas/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 simple iOS view to play video]]></title>
            <link>https://medium.com/@rodrigo_freitas/a-simple-ios-view-to-play-video-b7ee05f9ce6a?source=rss-b2543559991c------2</link>
            <guid isPermaLink="false">https://medium.com/p/b7ee05f9ce6a</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Rodrigo Freitas]]></dc:creator>
            <pubDate>Sun, 14 May 2017 15:36:47 GMT</pubDate>
            <atom:updated>2017-05-14T15:36:47.246Z</atom:updated>
            <content:encoded><![CDATA[<p>A simple component that display a video.</p><h4>The VideoView component</h4><p>we need to create a UIView and customize it to display a video.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f48f42ce8ecb19022ef121a7060ff943/href">https://medium.com/media/f48f42ce8ecb19022ef121a7060ff943/href</a></iframe><p>Above we have your VideoView that can be configure with a URL to display the video. In the ViewController, we add two views and made them to be the VideoView. After we do it, we just need to configure and play the video.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4qoFqVN-sK4pTAdmn7ju0Q.png" /></figure><p>The code is in the github if you want check it out.</p><p><a href="https://github.com/frelei/VideoView">frelei/VideoView</a></p><p>Happy coding!!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b7ee05f9ce6a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CloudKit]]></title>
            <link>https://medium.com/@rodrigo_freitas/cloudkit-cdda2f725042?source=rss-b2543559991c------2</link>
            <guid isPermaLink="false">https://medium.com/p/cdda2f725042</guid>
            <category><![CDATA[cloudkit]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[apple]]></category>
            <dc:creator><![CDATA[Rodrigo Freitas]]></dc:creator>
            <pubDate>Thu, 19 May 2016 23:14:08 GMT</pubDate>
            <atom:updated>2016-05-20T01:50:17.908Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XZvXCcrnNCAAHiW5tOEb0g.png" /></figure><h4>Understand a little bit more about the Apple’s cloud — Guideline</h4><p>Today even the small application need store some information. Unfortunately, when we want create an application we know how expensive an application can be. We have to develop the design of the screens, the logic of the application and sometimes the server. Create a server and deployed on Amazon or Azure sometimes can be very expensive, when we just need to build an minimum value product and see if our ideia is right.</p><p>Cloudkit cames with a good solution when we need to build a quickly solution and validate your idea without spend one single buck. Of course, CloudKit can be use if your application became a huge success as well.</p><p>In this article, I will relate all my experience with the framework, all my understand how the framework works. Things that I liked and things I don’t like, the problems I faced and how do I fix them.</p><h3>What is CloudKit ?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m2hfDMaIL7FGdH1-G876bQ.png" /><figcaption>Cloudkit is the layer between your app and the server</figcaption></figure><p>Cloudkit is a transport technology that provides access to the apple server where all the information create by your users throught the app is storage. So every time the user save, update, fetch or delete some information the Cloudkit intercede and make all the communication with the apple servers.</p><h3>How do we start an application with CloudKit?</h3><p>We can start an application in cloudkit through <a href="http://developer.apple.com/">http://developer.apple.com</a>, in the left column you go to the section &quot;certificates and profiles&quot; then to the section &quot;iCloud container&quot;. The picture in the bottom shows the place where you can create a identifier which is going to be our container.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e-diNc1HCEoVfEfJEfeOqg.png" /><figcaption>Where you can create an identifier for the cloudkit container</figcaption></figure><p>The identifier is going to our container. The container identifier should have be prefixed with the word &quot;iCloud&quot; follow by your bundleId, for instance, &quot;iCloud.com.kobe.TDC&quot;.</p><h3>Enable Cloudkit Capability</h3><p>To enable Cloudkit in our application we need to go to XCode in the project on the capabilities section and enable. The picture below show the right place where we have to do this configuration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DUpewKxYtqdy1cgroLfRSw.png" /><figcaption>Enable Cloudkit in Xcode</figcaption></figure><p>When you enable iCloud section check if you mark the Cloudkit section and select the container identifier you create on <a href="http://developer.apple.com/">http://developer.apple.com</a></p><h3>Dashboard</h3><p>The dashboard is the place where you manage all your database structure. You can create schemes, record, subscription and also manage who can change any kind of information related with other data in the server.</p><p>You can access the dashbord throug the developer.apple or the XCode on the section capabilites showing in the picture above.</p><h4>Record Type</h4><p>The section record type is the place where you can create our table and the attributes(Field Name) that your table will have. For example, in this article, I will create two tables <em>Attendee </em>and <em>Section. </em>The picture in the bottom show these table created and some attributes configured with our field type</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7v8KeNDQI8vwPydYGJ9R5A.png" /><figcaption>Record Type Section</figcaption></figure><h4>Security Roles</h4><p>The roles section is the place where you can create new roles. For example, if you just want a specific user has the ability to delete you can add a role to that schema. In the picture below we can see the creation of a new role.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r5-cJ1z-AEZP-v9dlhKHUA.png" /><figcaption>Sectury Roles Section</figcaption></figure><h4>Subscription</h4><p>The subcription section show all the subscription that the users register. The subscription is one of the great features of the framework. The subscription allow us to inform the user that something happens in the database. For instance, Let’s imagine that we have a record session and we change the schedule of the session. If the user registered in the subscription, the cloudkit send to the user a notification with a custom message provide for us developers, informing that change happened in the database.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tmoRv5sgadOsLFX3oN9Hdw.png" /><figcaption>Subscription Section</figcaption></figure><h4>User Records</h4><p>The user records is the section where you can see all the users that use your app. In the picture below, we are not able to see more information about the user, actually we don&#39;t see any information, because your application need to ask to user to get more information such as name and email address. If you don’t ask we only know that a user uses your app. Apple takes the privacy of the user very serious. This information that your app request is related with the iCloud account.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ju1xpCQNFdzEaIGs62K-iA.png" /><figcaption>User Record Section</figcaption></figure><h4>Default Zone</h4><p>The default zone is the section where you can see all the record created by the community that uses your application. In this section you can create, update and also delete records.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*60Hsz7e_p3Q9GXR-840Upw.png" /></figure><h4>Usage</h4><p>The usage section allow us to check how many users, requests, asset storage and also other statistics to control if the application need more resource. For example, if we are getting more than 100 request per second, we need to talk to apple to get more resources.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dUj0XPizAlSmcOrpSmoRYg.png" /></figure><h3>CloudKit Objects</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XZvXCcrnNCAAHiW5tOEb0g.png" /></figure><p>Now we are going to check how we can access all this data through our iOS application. How in our app we can save, delete, update and perform complex operation on your application.</p><h4>CKContainer</h4><p>The container is the identifier where the cloudkit can find our application in the apple servers. We created it the developer.apple.com before. Each application have one container.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XmIp-uyoPNw4BJwhURSBLA.png" /></figure><p>In the code above, we can see how we can get the container from cloudkit.</p><h4>CKDatabase</h4><p>Every app access at least one container and each container contain two database one public and other private.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*unWRzQ1cby0N21hNkCTX_g.png" /></figure><p>As you can see in the above we have two database. Every client has your private database which is your iCloud account. As I told before you are not able to see the private data, the only one can access this data is the user. Once the user allow us to store information in the private database, be careful with this space, because we are using the store from user&#39;s iCloud account. So for us developer we see the database as the picture below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G1j5yisjIZDn-RHn24xFxQ.png" /></figure><p>To access the public or the private database we can get this throught the container. In the below I list some rules about the databases what are allow in each one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*enlT0Oo9yP_TYCwJy_xjTQ.png" /><figcaption>Rules</figcaption></figure><h4>Record</h4><p>The record is the data itself. You can think this as a row in a table. The records live inside of the database.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*EvOsqb_ptdLMkOQeLHn6Og.png" /></figure><p>A record is a structured data. It is similar as a NSDictionary where we have keys that is the field name that we create when we make the scheme and a value that is the type related with. The type of the values are those ones we are used such as plist types and also a new ones like CKAsset and CKReferences.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W16goVVu567FwXxKEpZumA.png" /></figure><p>So how do you can create a record.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0-Byovr-otDrRktSeeOu7A.png" /></figure><p>Pretty easy!!!! Well you may wondering I can subclass the CKRecord and do something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/1*Paz4FtXisyozwzhjRbpffg.png" /></figure><p>Not really. The apple documentation says:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3BDqJ81nnHQXVfZ4dKLJmg.png" /></figure><p>So what can we do? I am using this approach, we receive in the constructor a CKRecord and we use this reference and in our class we update the record every time we change the variable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*EL27YO3igVjq_dUJS5Noqw.png" /></figure><p>Just one more warning that is in the apple docs</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2QXFGBY-nchTn3LoBc5RRQ.png" /></figure><p>So be careful with the size on your CKRecord.</p><h4>CKReferences</h4><p>The reference is the way we connect the record so one session has one or more attendees.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*mHBkG3c17lcmlNQG90uSVw.png" /></figure><p>This make sense however cloudkit works with back references so the picture above is wrong and the right one is like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*4A3Zily-wj3utAiD-lxdLg.png" /></figure><p>The Attendee holds the reference to the session and we create a reference like as the code below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V3OubyHn_9jxUFGrDzbElg.png" /></figure><p>The parameter action in the constructor of the CKReference is to perform cascade delete if you pass the parameter .DeleteSelf, that means if we remove the parent the sons will be remove as well.</p><h4>CKAssets</h4><p>The CKAsset is the class represents large unstructured data and is owned by the CKRecord. So if we delete the CKRecord we loose the the CKAsset. The CKAssets is not store in the database. They are storage in a bulk store, but for us as developers this is transparent.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IFrjbvpYnRQqn5y5o5uDUQ.png" /></figure><p>So let&#39;s imagine the user take a picture from the camera and we want send this image to the server. To achieve this we need to do something like in the code below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XDKlkyvlQFZIb5xVqCZEDA.png" /></figure><p>We need store the image first. Pretty weird, right? It&#39;s necessary because cloudkit is smart enough to know if the user has the image. So if the user has the image, the cloudkit don&#39;t download again the image from the serve to save bandwidth.</p><h3>Login</h3><p>The login is a little different than we are used to. We don&#39;t perform a login like filled with your email and password. The user login in your application trought iCloud account, it means that if the user is login iCloud account on the device, the cloudkit automatically add the user to the table User Records, but remember it not show the user&#39;s info.</p><p>To check if the user is log in iCloud account on the device we have to use this method below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KH_4djpJ-udfRI8CPdQsTw.png" /></figure><p>Once we don&#39;t have a login screen we can let the user uses your app until we need it. When the user needs to create an record, for example, and the users don&#39;t have connect to an iCloud account we can to redirect the user to perform a login in iCloud account. The example below uses this aproach.</p><iframe src="https://cdn.embedly.com/widgets/media.html?url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DeQX_ePcE1PA&amp;src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FeQX_ePcE1PA&amp;type=text%2Fhtml&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/d13499b6302d3af901f879836541f674/href">https://medium.com/media/d13499b6302d3af901f879836541f674/href</a></iframe><h4>Convenience API</h4><p>The convenience API is an easy way to start perform save action with record such as save or update. The convenience API is a extension from CKDatabase as you can check below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BBy-yyuLnnObOGopdivKnw.png" /></figure><p>To save an record with the convinience API is very easy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3HTObHAyDvvjW6abStjQzQ.png" /></figure><p>As you can see all the methods from cloudkit are asynchrouns and for all of them we need to create a beautiful error handling as apple suggests. Of course we need to check the error because this is the diference between a funcional and not funtional app.</p><p>The convenience API is a good way to start as I said, but what happends if we need to get an object, get other object from a reference and update its value. We need to perform three request at least. Probably we get a code like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xdjdC0TaSw9HwOFGc1kQgw.png" /></figure><p>As we can see this code is a mess. One thing that we can use is NSOperation to save us. For our luck the cloudkit have a lot NSOperation called CKOperation. Cloudkit was built with a lot operation to avoid situation like that. In the example below we catch all the attendees from a session using CKOperations</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wj5IVXtRBkBx9zYRHjReUA.png" /></figure><p>In the code above, we create a operation to retrieve a session, when this operation is completed we start a new operation to retrieve all the attendees of the session. In the end of the code, we made the second operation depends from the first. We need to do this because if the first one fails we shouldn&#39;t call the second. The last but not the least we have to create a NSOperationQueue and add to it the CKOperation we have create it.</p><h4>CKQuery</h4><p>The CKQuery class is used when we want to get a slice from the database. To use this class we have to understand first the NSPredicate. The CKQuery uses a subset of NSPredicate to inform cloudkit which information to get, as you can see in the example above. Here we have a few rules, but we have a lot more, please check: <a href="https://developer.apple.com/library/ios/documentation/CloudKit/Reference/CKQuery_class/">NSPredicate Rules</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H8iW7Yqy4CrEHPIzKkRA1w.png" /></figure><p>Now image we want to retrieve some information, but we don&#39;t want get all information at once. We wanto to performa a pagination. This is a little bit trick how we do it in cloudkit</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1NhaS_c36UqmdFSrkLk9XQ.png" /></figure><p>To create a pagination we need to instantiate a CKQueryOperation with a query that we want to perform. We have to catch a closure in the queryCompletionBlock, if we have more results to retrieve this closure will return a CKQueryCursor and in the future we need instantiate again your CKQueryOperation but this time we have to instantiate with the cursor. The class above do this kind of operation.</p><h4>Conclusion</h4><p>The Cloudkit is a great tool if you want just validate an idea or use in production mode. I believe the framework needs to greatly improve and it will, because It&#39;s necessary for us, developers, this kind of tool because we can spend more time in your apps and not doing the backend.</p><p>Here is my first step using the framework. I am writing this to help others that have difficulty to understand the framework and how to use it. I know we have a lot material here, but cloudkit have a lot to cover yet, but it&#39;s too big the article so far!!!! Thanks.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cdda2f725042" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>