RealmExplorer – a piece of sample code for Realm DB

realmexplorer_01_smallFirst things first, look at the RealmExplorer github repo for the project.

Preface: CoreData

I have some history in using databases. From using Oracle, Frontbase, mySQL, PostgreSQL, sqlite etc. the last time I used a database was for a postcard app using CoreData. But I found CoreData to be a lot of overhead and boilerplate code to write.

Especially migrations are kind of not very intuitive to understand and if something goes wrong you are basically lost. While Xcode for a while had an Entity modelling tool (which had it’s roots in the WebObjects EOModeler), most of the time this tool did not work very well for me and had lots of bugs. In each Xcode version different bugs!

Also many people report running into issues when using CoreData with lots of objects, because it is easy to loose track of memory consumption with CoreData and if you do not actively check and work against that, you end up with a whole model graph being in memory. Not cool! So I wanted to try something different.

Realm

I found Realm by Realm.io to be interesting enough to tinker with. So I started working with their sample code projects. But none of those projects came even close to some real world example. So I just started prototyping something I will need for a different project anyway.

Starting with a custom viewcontroller for adding & editing entities I recognized that this would soon become rather painful to provide e.g. inputfields for text and numbers and dates. So I grabbed FXForms to give it a try after I had already completed a viewcontroller to manage DBCaptain entities a bit.

Migrations

Right from the start I wanted to know how migrations work. Because usually those are the weakest spot in every db operation taking place. With a live product you always „pray“ that nothing will go wrong during migrations on the customers device. And keeping track of changes to the db schema is very important to have a stable app.

So I built the sample around the process to „simulate“ an app in development. You can now iterate through different development steps (5 different app states & their migrations) and their needed migrations. This way I figured out how I can safely manage my migrations (i.e. always keeping a backup of the old schema). In the project the
DatabaseFactory.m class manages all that. It detects existing schemas using a precise naming scheme for each Realm-db created.

During app launch any necessary migrations are executed if necessary. Also, any errors happening while the app launches and gets into trouble activating the database, are nicely displayed.

Create/Insert/Edit/Delete

I started with one entity DBCaptain which is basically a user entity. I just wanted to create user objects and populate them with different properties. I tested insertion with one and with many users on the main thread and on the background thread. I also took advantage of notifications coming from Realm as soon as an operation finished updating the db.

Deletion of objects came next. As always having the UI keeping track of all those changes is the more difficult task. So expect some „ugly“ code, because this was only me tinkering around. When i wanted to edit existing objects I recognized that I do not want to create all those textfields manually.

FXForms

That was when FXForms came to the rescue. I started to recreate the already half done viewcontroller and created another based on FXForms. I needed some time to wrap my head around FXForms, because basically this is a quite sophisticated hack of providing compact descriptions of UITableViewCells and their content.

You describe what kind of structure your form should have and what kind of value types it should use. FXForms crafts the UITableView which makes all those inputfields come true. Things start to become a bit tricky if you want to control those UITableViewCells more directly. E.g. I needed a way to exclude certain properties of being edited at all. So I simply extended the FXForms protocol to allow for a denial of userInteractionEnabled on certain cells by adding the FXFormFieldEditable key. This is used on the CaptainFormViewController to exclude the information about the database schema and the encryption status to not be editable.

Evaluation

My first impression of Realm DB is quite positive. It is fast, it provides helpful error-messages and it is easy to setup and comprehensive in what it does and how it works. I never in my life had migrations up and running that quickly. Very, very helpful was the Mac app RealmBrowser to open a realm DB file directly. I used that while checking my migrations and the results of operations which added arbitrary data (e.g. image files).

What is actually really great is that encryption is supported for the db by just providing a 128 bit key. That is really helpful to protect user data and increase safety of the realm db file even if it gets backed up into some cloud somewhere else.

What’s next?

I think I missed something related to the KVO-thingy going on by Realm. But I had no time until now to figure that out. I suppose they actually track entities and changes via KVO. But I am not yet sure how exactly this works and how I can detect if an object has pending changes. That is why I added a hasPendingChanges BOOL-flag to both ViewControllers for editing entities. So help is welcome here!!

I did not have time to do some real hardcore performance testing, i.e. adding thousands of entities and relationships in a short time and crafting a rather complex model with complex relationships which define ownership and cascading deletions etc. Also doing sophisticated db queries is on my list to do next.

But having a prototype now to tinker with helps already a lot. Since I learn best from sample code, and I think I am not the only one learning new things this way, I hope it helps others to jumpstart with Realm, too.

Why do I blog this? I just wanted to give a bit of background info on the sample code I put on github. Have fun tinkering & I am really in need of getting more info on how I can detect changes to an object so I know WHEN to save changes to the db. Maybe someone who already grabbed the concept better can help me here?? Leave a comment or contact me via github.

The Art of Manliness

Orientierung für Männer ist heutzutage angesichts des von allen Seiten unter Druck geratenen Männerbildes ein knappes Gut geworden. Es gibt kaum noch exklusiv Männern vorbehaltene Orte, an denen sich Männer auch tatsächlich Mann-spezifischen Entwicklungen in einem geschützen Raum widmen können ohne gleich in komische Rechtfertigungszwänge gegenüber unserer überkorrekten, übervorsichtigen, risikoaversen Vollkaskogesellschaft zu geraten.

Umso schöner, wenn es solche kleinen Oasen mit viel interessanten Inhalt dann doch noch im Netz gibt. Eine solche habe ich per Zufall vor kurzem gefunden: www.artofmanliness.com

Ich zitiere daraus mal einen mir sehr wichtigen Abschnitt, den ich nur unterstreichen möchte, zeigt er doch, woran es vielen Exemplaren Mann derzeit am meisten fehlt. Vor allem Jungs die allein von der Mutter, der Kindergärtnerin und der Grundschullehrerin erzogen werden. Menschen die diesem Jungen beim Anblick eines Messers sagen „Pass auf das ist scharf, damit schneidest du dich nur, leg das weg!“

Rite of Passage

Across time and place, cultures have inherently understood that without clear markers on the journey to manhood, males have a difficult time making the transition and can drift along indefinitely. Thus, rites of passage were clearly delineated in nearly every culture as one of the community’s most important rituals.

Wir selbst müssen die Veränderung sein, die wir in der Welt sehen wollen

Das (PDF | Depublizierungsschutz) sagte einst Mohandas Karamchand (Mahatma) Gandhi und ich finde die Empfehlung nicht schlecht. Die abhanden gekommenen Riten, die einem den Übergang zu & Status als Mann und zugehöriger zu den Männern klar machen, sollte man nicht einfach hinnehmen. Wenn etwas fehlt, dann sollte man sich drum kümmern, dass es (wieder-)beschafft wird.

Ich denke daher, dass Männer jeden Alters sich heutzutage selbst um einen „Rite of Passage“ kümmern müssen. Die Väter kriegen es in aller Regel gar nicht auf die Reihe und sind mit sich selbst beschäftigt, und die Mütter können das nicht tun, da sie nicht der Gruppe der Männer angehören.

Rite of passage is a celebration of the passage which occurs when an individual leaves one group to enter another. It involves a significant change of status in society.
Quelle: Wikipedia

Ich denke daher, Mann sollte sich seine eigene Rite of Passage-Challenge erarbeiten und durchziehen. Etwas vor das man sich fürchtet, etwas was eine Spur hinterlässt die man zeigen kann, etwas was einem zu jedem Zeitpunkt danach wie eine Art Anker wissen lässt und versichert, dass man diese Passage gemeistert hat.

Über die Kuh hüpfen

hamar_cow_jumping_rite_of_passage_250Im äthiopischen Stamm der Hamar ist es z.B. üblich, dass man erst dann von der Gesellschaft als Mann anerkannt wird (als Vorbedingung die Heirat eingehen zu dürfen), wenn man über eine Herde Rinder gesprungen ist. Eine durchaus fancy Challenge wie ich finde, mit einem tollen Bild rechts.

Bei dem Höhepunkt dieses Rituales springt ein junger, uninitiierter Mann (ukuli) viermal nackt über eine Reihe von Rindern, um heiratsfähig und erwachsen zu werden.

Interessant ist bei diesem Ritual dass es bei den Hamar eine Art Gleichberechtigung gibt, denn auch die Frauen werden Teil des Rituals und tragen durchaus Spuren in Form von Narben davon. Näheres liest man am besten selber in der Wikipedia nach.

The Modern Primitive

Ein Teil der angesprochenen Dinge, insbesondere der Prozess eines Übergangs in Form eines Rite of Passage, wird oft auch wiedergefunden in einem „Way of Life“-Konzept das sich Modern Primitive nennt oder auch Primitivism. Dabei macht man als zivilisierter Mensch Anleihen bei eher „einfacheren“ und „ursprünglicheren“ Konzepten des Zusammenlebens und fremden Kulturen, wie eben z.B. bei autark lebenden Stämmen wie den Hamar.

Why do I blog this? Ich denke, dass die vielen orientierungslosen Männer auf diesem Planeten keinen Übertritt zum Mann-sein mehr erleben können und das genau dieser Umstand eine der Hauptursachen für eine Nichtverankerung in der Gesellschaft und in der Rolle als Mann darstellt. Das Kulturgut und die elementare Funktion dieses wichtigen Schritts ist weitgehend untergegangen, obwohl es eine so wichtige Funktion für die gesamte Zukunft und Lebensgestaltung eines Individuums ausfüllt. Ich habe sicher auch kein Patentrezept, was deine persönliche „Rite of Passage“ sein wird, aber bei einem bin ich mir sicher, es sollte sie mindestens einmal im Leben eines jeden Jungen/Mannes geben. Wer wie viele junge und ältere Männer heutzutage Mitglied im Club of Dadfails™ ist, dem könnte eine ganz persönliche Rite of Passage einen Weg offenbaren sich selbst zu verankern in der Gesellschaft und sich der Zugehörigkeit zu den Männern jederzeit sicher zu sein. Ein Quell der Sicherheit & Orientierung durch Verankerung, der seinen ganz eigenen Wert darstellt in einer Gesellschaft deren ständiger Wertewandel für genügend Verwirrung jeden Tag sorgt.

Undiplomatic UIKonf 2015 Retrospection

uikonf_2015

I was in Berlin. At UIKonf 2015. My first UIKonf. Just some links and ideas before they fade from memory… Trigger warning: I always have a strong opinion on things and little time/energy left to rephrase them in a diplomatic way. …and one thing before I start: I really liked the UIKonf experience. Very well organized, great location, easy to navigate in Berlin, awesome social events, interesting insights into our community. I really enjoyed it!

Mike Lee

First talk by Mike Lee was about our future on Earth. He actually did something marvelous, he transformed a scientific paper into a keynote presentation which communicated the content of the paper in just 30 minutes to people usually not used to deal with science everyday. That is awesome! At the same time this keynote shows the gap between the issues we right now deal with and solve as a developer and the issues we maybe should care about and solve to rescue our planetary existence.

Mike Lee at UIKonf 2015


Source: List of UIKonf Videos 2015

A paper about Human-Nature Interaction in World Modeling with Modelica as PDF (Depublizierungsschutz). There are more publications available on the „Principles of Object-Oriented Modeling and Simulation with Modelica“ which was used to model the world after the research results of the Club of Rome. It’s also interesting to give www.donellameadows.org a visit. Mike’s talk actually had the most impact on me.

Reminded me of this…

king_midas_in_operation
Source: ink361.com

…this…

human_evo
Source: sustainablehuman.com

…this…

pandora_tree_of_life_souls
Source: Movie Avatar/Pandora

…and this…

evo_extinction
Source: evogeneao.com

Exkursion: Don’t panic!

If you prefer to listen to some Don’t panic!-talks by Hans Rosling which focus on one single variable instead of interconnected complexity, please do so, but please consider reading the news and check how Hans Rosling does very elegantly manipulate you to think everything will be okay by using his extraordinary presentation skills.

logarithmic manipulation

I pretty much dislike tricking people by using log-scaled values to actually make gaps vanish, but maybe the name „gapminder“ is basically telling truth about what they actually do. I once really adored Hans Rosling for his extraordinary communication skills to explain & entertain at the same time. But I slowly feel he just started loving his own graphs and the beauty of graphs more than the truth they are telling. Especially when he log-scales the income, he intentionally hides inequality and that is a very unsocial perspective. But Rosling does opportunistically switch scales if it helps him making a point.

Switching scales like you need

Here he just switches to a linear scale (or completely leaves out any scale at all) to display that airplane traffic uses up half the fossil fuels burned. Had he used a log-scale here, to also hide the inequality he never would have been able to make his point clear. But actually the linear scale here tells the truth. Ask yourself, why he doesn’t use it for the comparison of the income.

But back to UIKonf

…the other talks which touched me in short words and sentences…

…following stuff to be continued, extended & updated soon…

Tom Adriaenssen

Do it asynchronously without rocket science… and profit. I really loved this talk.

This is a standard problem every developer faces: Loading data and asynchronously updating the UI. Even Apple fails often and miserably at this in their own apps. Tom presented a standard solution to be applied to it. That is much more than I expected. Great to see a solution to this well known problem. Now I just need to get to know this solution to implement it.

Ash Furrow

That’s what I do, and it helped me, you might care too. This talk was well balanced and really stroke a chord in me. Since I blog for over 10 years now, I found this was really was a talk telling truth. My blog was always more a private repo in the public than a business tool but well… maybe I just are bad in business. Who knows! But actually if I can choose between stackoverflow and a blog I would always choose the blog.

Halle Winkler

How I do it and what I do not do anymore and how that allows me to make a living… still on the edge. This was a developer closest to my own situation. I would not call myself an „Indie“ though, I am a franchisee and my franchisor is called Apple Inc. Though my apps perform quite okay, I totally felt all the pain Halle was expressing in the talk. I have huge respect because I know how difficult that is to be on your own to keep up a business.

JP Simard

Attention / Trigger Warning: Warning issued above applies especially here!

It’s not Apple’s fault they introduced a language without the proper tools being available it’s just pretty straight forward you know. It’s your fault not fixing it. Community. Community. Community. Do what I do. Community. Community. Look I do it. Community. Community. Though no one will pay you and Apple is a profit oriented company avoiding risk at all costs, you should go full risk, risk the time of your life to be sherlock’d by Apple and fix Apple’s bugs. Because you know, Community, Community, Community. We are *not* profit oriented like Apple, we are all idealistic and we love to fix the worlds problems right? Community, Community, Community. Do tools! Apple is great!

Marcel Weiher

We still did not make any progress in reusing software components after all those years.

marcel_weiher

I am a huge fan of Marcel Weiher, because of one single small app: PdfCompress 6.3.1 It is one tool of a kind I still use now for all those years. And it still solves problems for me when sending huge PDFs. I have huge respect for Marcel, because he is actually a part of my everyday work.

Graham Lee

Let’s do the time warp again! Those unwilling to learn are doomed to repeat history. Welcome to a new 20-year-repetition-loop in 2015.

All the slides

This is the same issue which happens to each conference always: „Do you have your slides anywhere online?“ Nowadays slides are no slides anymore… they are small amounts of data spilled all over the web. So from slideshare to speakerdeck to github, blogs, and everywhere else…

So I went into my HTML editor, scraped the table from the UIKonf website and then went to twitter and slack to research for all your slides and removed enthropy.

Oh and btw, here are the videos of UIKonf 2014 and the slides of UIKonf 2014.

UPDATE: All the videos from 2015

From the proposals the following talks were chosen.

Mike Lee World Modeling youtube
Natasha Murashev Swift Thinking slideshare
Eli Perkins Staters Gonna State github/pdf
Junior Bontognali Monads are not Monsters speakerdeck
Claus Höfele Practical WatchKit Development speakerdeck
Marcel Weiher Software Architecture in iOS and OS X applications github/pdf/keynote
Tom Adriaenssen Async View Controllers speakerdeck
code
github/pdf
JP Simard Fixing the Swift Tooling Problem speakerdeck
Ash Furrow Teaching and Learning speakerdeck
Halle Winkler Duct-taping the gates of chaos shut: the weird, little, useful, sustainable indie (by design) other/blog
NSConf7/video
Brian Gesiak iOS API Design: Swift Patterns speakerdeck
keynote
Joe Burgess Learning Swift Through Lessons in Haskell github/pdf
Chris Eidhof Functional View Controllers github/code
Hector Zarate iOS at Spotify: From Plan to Done youtube
Jens Ravens Functional Reactive Programming without Black Magic – Build your own ReactiveCocoa from scratch slideshare
Saniul Ahmed Prototyping Touch Interfaces (and my open-source story) prototype
math
Maxim Cramer A Journey into Design speakerdeck
Graham Lee Object-Oriented Programming in Objective-C blog
Nick Lockwood React Native dropbox

Talks I would still like to listen to…

This is my favorite collection of talks which were not chosen from the cfp.

Others reflecting & new blogs

Note-2-self

I really need to transition my wordpress installation to Ghost. It’s so much cleaner and really fresh compared to my dated non-responsive theme. But at the same time I would loose all the advantages of being able to write HTML in my posts. But being able to copy some HTML elsewhere and dropping it in my posts is essential for my work. Also writing in markup only is not favorite thing to do. So after having visited Ghost’s specs I think Ghost will not be the right direction to go. Maybe a better wordpress theme will be the better way to go…

Why do I blog this? Ash Furrow hold a really great talk about blogging at UIKonf. I really appreciated it a lot and was reminded of my own blog I now have for more than 10 years. So I just want to take some notes related to UIKonf.

I found it quite refreshing to set things into a perspective to the whole world. That is what Mike Lee did successfully. Many people may have disliked that, because it confronts them with an inconvenient truth derived from data. But that is why I liked it so much, it was an interruption to the business as usual happening in the software industry for years now.

I also liked the talk by Graham Lee a lot. Someone actually took the time to have a look back to where we started. Seeing how Apple will now repeat the same error again was worth the time travel back into the year 1995 (That was when I entered university).

I liked a lot of the talks but explicitly disliked the talk by JP Simard because in my humble opinion it was pure propaganda and Apple whitewashing. It was really hard for me to listen to this and upset me quite a lot.

I also disliked all the very code-centric talks about swift. Source code is not per se something that fits into a presentation. Reading and understanding code burdens the visitor with way above average attention and imagination under high pressure to do all this in a short period of time (the time the slide is visible). Usually it is not possible to process the code presented in this short timespan, especially if the speaker elaborated on this piece of code for weeks.

That is why I disliked all the swift talks. None of the swift talks I listened to, did emphasize a broader perspective. They all lost themselves into the details of the grammar of a new language. I would have really enjoyed a talk about „Mastering Transition“ from Obj-C to Swift, but nobody seems to care about this. though all developers in the room are actually living this transition right now.

Raving about language details this early in swift-language-history was completely lost time to me. The guys explaining monads? For me they are just winging it. IMHO, the really important things about swift were missing at UIKonf. If there wasn’t Graham Lee, I would have been completely disappointed by the talks taking care of the new language & paradigm dropped upon the developer community.