Prioritize your network connections in macOS

If you are working with a MacBook Pro or similar you usually have really fast wifi but there are still situations, where a wired network connection is preferred like working with images from a NAS like in my case. To get the fastest connection possible, I bought a USB3 to gigabit ethernet adapter which is plugged in when I am working on my desk at home. Disabling the wifi connection isn’t an option because this would also disable AirDrop and other features I use often.

So how can this “problem” be solved? The solution is very “Mac like”: Just open System preferences, go to Network and click on the little gear at the bottom of the interface list then select “set service order” (see image below). By dragging the wired connection on the first position, followed by the wifi connection your Mac will prefer the fast connection for anything network related but gives you still all the features which depend on the wifi connection!

 

set service order of network connections

WWDC 15 – The Aftermath

wwdc15

WWDC 15 is over for some days now and I think it’s a good time to write down some thoughts about the things Apple showed to developers. I couldn’t attend at Moscone but watched the Keynote and will have a good time with a lot of the session videos. As regularly, at WWDC Apple shows all the new stuff for their operating systems as there are OS X, iOS and new for this year: watchOS. I’ve got my first Mac almost 10 years ago (when Tiger [10.4] was the current version of OS X) and always have a critical view on new features, technologies and so on. The experience I had when using the Mac for the first time after so many years on Windows and some years on Ubuntu Linux was overwhelming. Finally somebody did everything right – a clean, simple and well thought user interface standing on a robust foundation, intuitive applications and a lot more… With growing so rapidly the last years I’ve always had a bit of a “fear” that Apple could lose it’s path and become the next Microsoft – I was wrong!

For me one of the most important things of WWDC is that iOS 9 and OS X 10.11 will be all about stability – even if I don’t have any problems on 10.10 I can spot a few things where the overall consistency lacks a bit. On iOS there are some bugs that aren’t often but dampen the experience on iOS in some way – as an example I have to restart Mail.app after some days of usage because it will not receive any new mail. I do not have crashes of the system at all or any serious bugs so I think this is complaining on a very high level. But that’s exactly where Apple was when I switched to the Mac and I believe that’s exactly there where Apple should try to stay. Focusing on rock stable systems is key to succeed with further development and the rise of new technologies. But there was more to show, so let’s dive right in. Here are my personal favorites of WWDC15:

 

Metal

When I saw the introduction of metal and the first demos last year I really was blown away – console like quality on an iPad? Awesome!! It’s great to see that Metal is coming to OS X too and even better to see that it will power the graphical effects of both iOS and OS X. I think this will be a huge improvement on speed for a lot of systems and applications. Even the fact that companies like Adobe will implement it into their applications is big news – relying on CUDA was only nice on Windows as we know today. I think it’s a kind of paradigm shift in general to design graphical applications like game engines platform independent and let them choose the “right” framework on the system they will run. Unity 3D is a good example for this – you can write your shader as you like and Unity will compile them for the targeted system – Mac / Windows / Linux / iOS / …so you do not have to struggle with this. The API which is used on the target platform can then be optimized for the hardware it is running on like on consoles. This leads to a big improvements in both performance and features! Shame on me – I did not found the time to play around with Metal since last year but I promise this will change soon!

 

Swift 2.0

Swift seems to become the major programming language on OS X and iOS (and watchOS). I grew up learning C and C++, do a lot of C# at work and always struggle when I am on Objective-C. I do not really know why – maybe it’s because of the different syntax on methods – but I’ve never became a good friend of it so I was positive about Swift since the introduction last year. Seeing a new star on the horizon with a lot more comfort on the programmer side is really good but I didn’t do anything productive with it because I felt that the development of Swift will change a lot and I am too lazy to update my code after every new release of Swift. With version 2.0 this feeling is gone, I think it’s a good time to switch since a lot of frameworks offer Swift compatibility now and the language itself seems more mature. The last new language I learned was processing and it fascinated me by being so simple and fast for prototyping – I just write your code and you instantly see a result – no need for a lot of writing for simple tasks as it is in C++. Combining this with the speed of C and a lot of well developed frameworks and voíla – there you have Swift! Oh and the argument that it is only platform specific for Apple was no argument for me because it’s nearly the same with Objective-C! Swift will be OpenSource so I believe it will be available on every other big platform too soon.

 

watchOS 2

I preordered an Apple Watch on day one and I was sceptical since I received mine but I don’t regret it for a single moment. Since I’ve got the watch my iPhone stays in may bag almost the whole day. It’s a new category of devices which will bring up new ways to communicate and get work done that we can’t think of today. Also the features for health tracking are great – it keeps me motivated to move more throughout the day and do some workout after a long day in the office. With the introduction of watchOS 2 and the ability to access more features of the watch for third party applications like the Taptic Engine and also bringing new frameworks like CoreMotion let us developers do exactly the things we thought of initially when Apple introduced the Watch last year. At the moment I am planning two or three completely different apps that I think will be great on the watch – at least for me and maybe for some other people too. To introduce new abilities for developers with time and to not open the whole system from day one is a good move as I believe – it gives developers time to get in touch with the device and also let the users become familiar with the Watch before getting flooded by a lot of apps that aren’t working as they expect. With the introduction of watchOS 2 the Watch will be an even more powerful tool as it is already today!

 

There are a lot more things I am excited about but I think these are my three favorites of this years WWDC. I can’t wait to get my hands on all the new stuff and to watch the session videos but as always time is to short! Apart from this I think iOS 9 and OS X 10.11 will bring a very strong foundation to keep the platform up to date and to rely on in the next years. As is mentioned earlier I think that slowing down the “feature after feature” cycle and big changes from the last years will pay out great!

 

Tutorial – Get the day of the week with NSCalendar for any NSDate

NSCalendar is a mighty class which let you do a lot of different things with NSDate. At first it might look a bit complicated but with some time it gets very useful when working with dates (especially with NSDateFormatter). As language I will use Objective-C but translating it to Swift shouldn’t be too hard.

So if you want to know which day of a week a particular NSDate is you have to create a NSCalendar to work with. To do all the date related stuff you also need a NSDateComponents object where you define how to work with the calendar. With them we create dates for a particular week in were our date is and loop through them. In every iteration we check if the created date is the same as our original date. I’ve created a function for date comparisons since I need them regularly often in my app. You basically just compare the single components like day, month, year, hour, minute,…

//Create our NSCalendar to work with
NSCalendar *gregorian = [[NSCalendar alloc]
                             initWithCalendarIdentifier:NSCalendarIdentifierGregorian];

    //Week starts on Monday in Europe! People in the US can comment the following line out.
    [gregorian setFirstWeekday:2];
    
    //get today
    NSDate* today = [NSDate date];
    
    //We need the dateComponents to do work with our NSCalendar
    NSDateComponents *dateComponents = [gregorian components:(NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitWeekOfYear | NSCalendarUnitWeekday ) fromDate:today];
    
    // Loop through week
    for (int i = 2; i < 9; i++) {
        //Set the weekday and create a new date from it
        [dateComponents setWeekday:i];
        NSDate *weekDay = [gregorian dateFromComponents:dateComponents];
    
        //Compare the new date with our "today"
        if ([DateFunctions isDate:weekDay equalWith:today]) 
        {
           //Do your stuff here, day of the week is i
        }
    }


So with this little piece of code you are able to determine which day of the week your NSDate object is. I hope this will be helpful for you, if you have any questions feel free to use the comments below!

Reset an Apple Wireless Keyboard

If you need to pair your keyboard with another device or a new computer and the wireless keyboard won’t go into “pairing mode” there is one nifty trick to force it to do so: Power on the keyboard and DO NOT RELEASE the power button. Now complete the pairing process while still pressing the power button.By doing so you will be able to pair the keyboard with the device you want to.

This great tip was found on Dave Meehans Blog.

How to install new Xcode themes

If you are not that satisfied by the default syntax highlighting in Xcode and the pre installed themes aren’t that useful for you there is an easy way to install some new ones. At first, open Finder and navigate to:

~/Library/Developer/Xcode

(to do so press cmd+shift+g and type in the folder). now create a new folder called

FontAndColorThemes

You are now ready to color up Xcode with new themes. To find some a good starting point to search on github.com for “Xcode themes”. Typically you will find a file with the ending:

.dvtcolortheme

Copy this file to the newly created directory. If you restart Xcode now you will see your installed themes under Preferences-Fonts & Colors. If everything went fine it should look like this:

fonts_colors

Macintosh turns 30!

Today in 1984 the original Macintosh was released! This was one year before I was born. Incredible what happened since then.

Apple made a very nice web site according to the anniversary, have a look: http://www.apple.com/30-years/

Also you can download a font where the characters are all Macintosh desktops and notebooks made until today (via osxdaily)

font

Reach for the million…

Mein neuestes Projekt ist nun mehr oder weniger abgeschlossen. Ziel war ein Partikelsystem, welches komplett auf GPU Basis agiert. Das bedeutet, dass das komplette Partikelsystem über GLSL Shader gesteuert wird, der C++ Code dient nur als Rahmenwerk zur Anwendungserstellung und Initialisierung aller benötigten Teile.

Auf meinem MacBook Pro (late 08), in dem eine Geforce 9600M GT schlummert, schaffe ich mit 1.048.576 Partikeln immerhin 29 Frames pro Sekunde, der PC mit einer Geforce 250GT sogar 60 Frames. Das ist ein ziemlich beeindruckendes Resultat bezüglich GPGPU Programmierung wenn ich daran denke, dass mein altes Partikelsystem (CPU) schon bei ca. 25.000 Partikeln mächtig einbrach.

Die Basis des Systems ist ein Ping-Pong Framebuffer, also zwei Framebuffer, aus denen abwechselnd gelesen und geschrieben wird. Beim Anwendungsstart werden zudem vier Texturen erstellt welche die Initialisierungswerte für die Partikeleigenschaften (Positionen, Geschwindigkeiten, Alter, Masse,…) und das Vektorfeld beinhalten. Das Vektorfeld lässt die Partikel um den Koordinatenursprung rotieren (link) und wird nach der Initialisierung nicht mehr verändert. Zusätzlich wird aber noch ein “Dummy” Vertex Buffer Object benötigt, welches genauso viele Punkte beinhalten muss, wie das Partikelsystem anzeigt. Ansonsten beschränkt sich die cinder App darauf, Tastatur- und Mausereignisse abzufangen und den üblichen Kram zu erledigen.

Herz des Ganzen ist ein Fragment Shader, welcher die Berechnung der Geschwindigkeiten und Positionen der Partikel übernimmt. Der Shadercode ist bisher jedoch ziemlich einfach, außer den Zugriffen auf die Texturen, den (einfachen) Berechnungen und dem Erstellen neuer Texturen passiert hier nicht viel. Ein Ziel für die Zukunft wäre natürlich noch komplexere physikalische Vorgänge wie Bewegungen in Galaxien oder Flüssigkeiten zu simulieren, für dass Herantasten an die Thematik soll es jedoch genügen.

Der zweite Shader dient nur der Darstellung der Partikel, hier werden abhängig vom Alter die Größe und Sichtbarkeit eines Partikels definiert. Mit wenigen Anpassungen kann man aber auch hier interessante Resultate erzielen, wie zum Beispiel das Einfärben eines Partikels bezüglich seines Ortes…

Zum Abschluss bleibt zu sagen, dass GPGPU Programmierung ein Riesen Spaß ist, auch wenn der Einstieg einiges fordert. Das nächste Projekt wird sich wieder mit der Kinect beschäftigen und dann geht auch bald die Diplomarbeit los, also wie immer…stay tuned!

Add TRIM support for Mac OS X

Apfeltalk reported about TRIM Enabler from Oskar Groth, I tested it with my OCZ Vertex II 120GB and it seems to work. Although someone on the OCZ forum who was involved in the Mac OS filesystem development said that TRIM wont help on Mac I’m interested in the results. Get TRIM Enabler here!

Oh, and a big thank you to Oskar!