(English) NSLocalizedString in Swift

NSLocalizedString gibt es auch in Swift. Man muss nur das „comment:“ Label vor den letzten Parameter schreiben, denn die anderen Parameter, die die Funktion ausserdem noch kennt, sind alle Optional (und so weiss Swift, welcher Parameter gemeint ist). Beispiel:

let text = NSLocalizedString(„Your Text“, comment:“ Your comment“ )

Zitat Schülerpraktikant

Wenn einen der Schülerpraktikant fragt: „Gibt es in Swift auch so etwas wie statische Klassen wie in Java?“, dann weiss man, …
– Hier hat einer was schon ziemlich gut verstanden
– Es könnte sein, dass dieser Schüler mal ein Programmierer wird
– Solche Sätze sind der Grund, warum wir uns mit Schülerpraktikanten belasten. Und warum wir stolz darauf sind, das zu machen

Übrigens: Wer nicht versteht, was gemeint ist – egal. Ich glaube man kann auch als Nicht-Programmierer ahnen, dass das ein ziemlicher Fach-Satz von einem Jugendlichen ist.

Und zuletzt die Auflösung der Frage: Ja, die gibt es, sie heissen „Type Methods“, werden func class mymethod() geschrieben und myclass.mymethod() aufgerufen.

Xcode Project breaks after png added

From time to time we have pupil interns. Our last intern, let’s call him John started some Xcode Swift programming and all was fun and great. After more than a week of successful programming small pieces of this and that he created a png picture file using the gimp editor. He then pulled the file into the project and from that minute on, Xcode did not want to compile any more.

It turned out, that the problem was the copypng perl script used by Xcode (found here: Programme ▸ Xcode.app ▸ Contents ▸ Developer ▸ Platforms ▸ iPhoneOS.platform ▸ Developer ▸ usr ▸ bin). Since the intern had created a subdirectory called John`s programs, he had a directory name with not only a space, but also a capital letter and a quote in it (I can not guarantee the particular type of quote any more, but I think it was the one I used above).

When I think back of the times where just on of the three was forbidden or problematic, I still shiver and I have to admit, that I am still a little bit superstitious regarding the use of blanks in directory names, even nowadays.

It turned out, that while compiling the swift files with that quote char in the file name did work, it did not work for the copypng perl script.

We changed the directory name and all went well a second later.

Swift und Core Data Problemchen

Letztens haben wir core data zu einem Swift Projekt dazu getan, indem wir einfach mal ein Core Data Modell per Drag-and-Drop dazu packen. Leider übersetzt Xcode das so dazu gefügte Modell nicht korrekt. Ein neu erzeugtes Modell in das wir die Entity-Definitionen des alten Modells hineinkopiert hatten, funktionierte dann aber problemlos. Merke: Beim neu anlegen von Core Data Modellen wird mehr gemacht, als nur eine Datei erzeugt.

Als dann der Zugriff auf die per Editor->Create NSManagedObject Subclass erzeugte Klasse nicht funktionierte, erinnerte ich mich dann glücklicherweise nach ein paar Minuten, dass ich ja in dem iBook „Using Swift with Cocoa and Objective-C“ gelesen hatte, dass man den Projektnamen in die Klassendefinition dazu schreiben muss, weil Swift ja kein flaches Klassenmodell hat, sondern bei einer Klasse den Namen des Projektes voranstellt.

Kaum hatten wir das gemacht, funktionierte alles. Ich frage mich nur, ob die Entity jetzt auch noch mit Objective-C funktionieren würde. Aber das probiere ich ein anderes mal.

Beware of iPhone „Restrictions“ mode

When sitting in a cafe with two other smartphone users, we spoke about „kids-safe“ restricted mode in the different smartphone systems and how they differ from the restrictions mode in the iPhone. In order to demo (and try it out), I did set my iPhone in the restrictions mode „on“ and we analyzed and nodded about nearly all the features.

What surprised my, was, that my self-programmed apps where still there – obviously you have to load them from the app store or my apps where missing some information that app store apps have e.g. like age restrictions.

Then it was time to set the settings back to normal and there came the shocking moment: All Icons were in disorder, they had left their groups, the sorting in the home-screen pages on the iphone were a mess.
I wondered, what would have happened, if I would have had so much icons that the sheer number would not fit on the screen, because I had them all grouped? If you know, feel free to comment.

Of course, I could have made a backup, or re-loaded a previous backup, but unfortunately, I did not know about this hazard and I already had made changes after my last backup a day ago.

So my learning from this experiment: Kids restrictions settings are not for temporary use. If you want to hand over an iPhone to a kid, put it in restricted mode only, if you can live with the disorder afterwards or if you had over the iPhone for a longer time. Or make a backup before handing over.

Black hole

When I recently did some programming while riding in the commute train, I added an new image view, added an outlet using the Assistant editor of Xcode 5 and started to test my program. All worked well, I added a few changes and had to hop off the train.

Some hours later I continued testing and was surprised to see a black window instead of my app. I could not remember what I had changed last time. Could it be, that I had made mistakes in the connection of the scenes? Did not look like so. Did I make a mistake in the code? No evidence for that.

Then I finally saw it:  Instead of putting the button to hidden, I had put my image view to hidden. I had connected the whole view,  instead of connecting the button only  – without noticing it. This meant, I had set the view that was meant to be the background to hidden and thus I had a black view into the endless dark black hole of the background behind the background.