Recent Updates RSS Toggle Comment Threads | Keyboard Shortcuts

  • danielsaidi 4:05 pm on February 4, 2010 Permalink | Reply
    Tags: Shared libraries   

    Using shared libraries with your iPhone app 

    After a couple of evenings, my first (really simple) iPhone app is taking shape. However, since I have my heart in .NET development, it is painfully clear how Microsoft has spoiled us with fantastic features of the oh so great Visual Studio.

    Some things that are natural and so easy to accomplish in .NET does not come so natural with the iPhone SDK. One example is to gather reusable functionality in shared libraries. With the iPhone, it is not as easy-going as when developing in .NET.

    I have found several blog entries that describe how to accomplish this. One good example is:

    http://www.clintharris.net/2009/iphone-app-shared-libraries/

     
  • danielsaidi 11:53 pm on February 1, 2010 Permalink | Reply
    Tags: data, retrieve, save   

    iPhone app – save data without database 

    I have now created my application UI, which has a nice tab bar which toggles between four different views.

    Now, I want to store a string that I have entered in a text field, so that the application remembers it the next time I start the application. I do not want to go through the hassle with using a database, since I will store so few objects.

    This great tutorial describes exactly how this is done:

    http://icodeblog.com/2008/10/03/iphone-programming-tutorial-savingretrieving-data-using-nsuserdefaults/

     
  • danielsaidi 6:54 pm on February 1, 2010 Permalink | Reply
    Tags: .nib, .xib, controller, Interface Builder, striped background, stripes, view   

    iPhone app – set striped background 

    So, I’ve finally begun looking into some iPhone development at my spare time. It’s good fun and I will write about my experiences here, as my work progresses.

    I first started to play around with was this good tutorial. After completing it, I thought I’d just replace the plain white background with the striped background that is so common in iPhone apps.

    Beautiful, striped background

    Beautiful, striped background

    However, no matter where I looked in Interface Builder, I could not find a way to set this striped background. Sure, you could insert a TableView, set its style to Grouped and let it fill the window…but I want the View itself to have the background.

    So, after searching around, I found that many developers set the striped background with either an image (which I will not cover since I do not want to use images when not absolutely necessary) or programatically.

    Option 1 – set the striped background programatically (“bad”)

    It is really simple to set the striped background programatically. Just do the following:

       //If you have a controller with the view, do this
       theController.view.backgroundColor = [UIColor groupTableViewBackgroundColor];
    
       //If you have the view directly, do this
       theView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    

    However, is this as good as it gets? This way of setting the background means that the stripes will only show when you run the application and not if you open the view in Interface Builder…and that just don’t do it for me :)

    Thus, I mark this option as a “bad” way of setting the default background. Naturally, you may want to change the background programatically for various reasons, but maybe not the default background.

    Option 2 – set the striped background in the .xib file (“good”)

    Well, I did not find a way to set the striped background in Interface Builder (if you do know how, please leave a comment), but it is really easy to set it by modifying the .xib file in a text editor.

    To do so, just right click the .xib file you want to modify and select “Open As > Plain Text File”. Then, in the text editor, search for the following tag:

       <object key="IBUIBackgroundColor">
    

    For a plain, white view, the section should look something like this:

       <object key="IBUIBackgroundColor">
          <int key="NSColorSpace">1</int>
          <bytes key="NSRGB">MC45ODQ3MTEyMDQ3IDAuOTg4NTMzNDAzNSAxAA</bytes>
       </object>

    Now, just add the following line as a sub tag to the object tag

       <string key="IBUIColorCocoaTouchKeyPath">groupTableViewBackgroundColor</string>

    so that the complete section looks something like this:

       <object key="IBUIBackgroundColor">
          <int key="NSColorSpace">1</int>
          <bytes key="NSRGB">MC45ODQ3MTEyMDQ3IDAuOTg4NTMzNDAzNSAxAA</bytes>
          <string key="IBUIColorCocoaTouchKeyPath">groupTableViewBackgroundColor</string>
       </object>

    That’s it – if you open the view in Interface Builder, you will now have a beauuutiful striped background.

     
  • danielsaidi 8:11 am on January 28, 2010 Permalink | Reply
    Tags: , ,   

    MacBook – MagSafe toggles green/orange (cont.) 

    I have some strange updates regarding the greeen/orange blinking MagSafe I wrote about yesterday.

    As I wrote, the LED on the MagSafe blinks between loaded (green) and loading (orange) even though my new battery is fully loaded.

    When I tried the battery in a friend’s computer, it worked…and while trying the battery at her place, it worked even in mine! Yet, when I returned home, the blinking re-appeared…and even continued when I tried another MagSafe connector. Straaaange times.

    However, an even stranger thing has happened since then. Before going to bed yesterday (after reading about exploding, blinking MagSafe connectors for hours) I decided to try installing OS X upgrades. They said something abot adjusting the computer for new hardware (strange) and then I shut it down for the night.

    When I started the computer this morning, the blinking had stopped! Either, my MagSafe connector is loose and the other I tried is loose or broken as well (quite unlikely), or I just had to install additional drivers for the battery. I do not understand a thing, but as long as the blinking have stopped, I am mr. Happy.

    Update: Now, at 10:30 am, the LED is blinking once again. It seems like the LED does not blink when I have had the MagSafe disconnected for a while…but since my neighbor’s MagSafe blinked with my computer, it seems to be an issue with either the computer or the battery.

     
  • danielsaidi 7:48 am on January 28, 2010 Permalink | Reply
    Tags: XBMC, XBOX, XOT-Uzg   

    XOT-Uzg – TV streaming on your XBOX 

    I recently picked up my old, black beast from the basement, where it has lived in solitude‚ since I bought the Wii, which I now have sold. So, since the Wii left an empty space, I decided to fill it with an old friend.

    Since I do not game on my XBOX anymore, I use it to play around with the XBOX MediaCenter software, which is great for chipped XBOX consoles. After I upgraded XBMC to the latest version, a friend of mine told me about XOT-Uzg, which is a script that can be used to stream web TV.

    XOT-Uzg screenshot

    XOT-Uzr running on another XBOX

    So, after installing the script, I noticed how the wonders of the new world appeared before me…as XOT-Uzg let me stream TV shows from Swedish channels as well.

    Now, my 1 year old daugher is watching “In the Night Garden”, streaming on the XBOX. It is sooo smooth. If you have a chipped XBOX, it is your duty to try it out!

    The only problems I have detected so far are:

    • You can not pause for too long, or XOT-Uzg loses its connection and exits the show
    • You cannot skip forward/back or fast-forward/backward

    The two problems in combination are quite annoying for long shows, but what the hey!

     
  • danielsaidi 8:31 pm on January 27, 2010 Permalink | Reply
    Tags: Battery, , ,   

    MacBook – MagSafe toggles green/orange 

    In my last entry, I wrote about all my problems with my MacBook (strangely though, this computer is by far the best I’ve ever had…which says a LOT about PC:s :)

    The last problem in the long list was that my battery swelled and had to be replaced. So, instead of buying a new Apple battery for about $190, I found a web site that sold “unofficial” batteries for almost half the price. Nice!

    After installing the new batteri and calibrating it, I was confused to see that my MagSafe adapter started to toggle between orange (loading) and green (loaded) although the battery IS fully loaded. The indicator reaches 100%, drops to 99% and goes on like this…on and on. So, I received a replacement battery and installed and calibrated it, but the problem remained.

    The way I thought, the problem could be either:

    • The replacement battery (two in a row = unlikely)
    • The battery together with my computer model
    • My MagSafe adapter
    • My computer’s battery connection (due to the swollen battery)

    However, if my battery would be loose, it would not be able to load…so…strike out the last alternative.

    To investigate this further, I took my computer to a friend of mine and installed the battery in her MacBook, where it worked like a charm…see below:

    • Her computer, MagSafe and battery = OK
    • Her computer and battery, but MY MagSafe = OK
    • Her computer, but my battery and MagSafe = OK

    So, this did not seem so promising…but when I re-installed the battery into MY computer, using MY MagSafe…it suddenly worked! Baffled (yet lucky), I returned home, where everything continued to work…

    …for a while. After two hours or so, the indicator started to blink once again! It still does so, so I am once again stuck with a MacBook component that does not work.

    If we boil this down to a summary, the battery seems OK, since it worked in my friend’s computer. However, so did the MagSafe, but…….is it possible that the MagSafe is damaged and that it happened to be “not loose” when I tried it out at my friend’s place?

    I will call another friend and ask him to come over with his MagSafe. If it works, it seems like I have to go to the place where I bought my computer and keep on struggling with this odd odd ODD MacBook example.

     
    • Johan 7:50 am on January 28, 2010 Permalink | Reply

      I was confused by your sudden change av språk.

      • danielsaidi 8:00 am on January 28, 2010 Permalink | Reply

        Ha ha ha, seems like I left a residue from the opinion I wrote on the reseller’s web site :) Thanks for noticing!

  • danielsaidi 7:15 pm on January 27, 2010 Permalink | Reply
    Tags: , Swollen battery   

    MacBook – swollen battery 

    I have previously written about my numerous problems with my white MacBook, which I purchased in August 2007.

    For instance:

    • the fan roared like a truck
    • the audio out port shone with a red light and thought that I had plugged in an optical device (which I had not), which turned of all sounds from the internal speaker
    • the chassi cracked(!)
    • the color wheel of death appeared every now and then, freezing the computer
    • the computer stopped waking up from sleep
    • the computer stopped recognizing my hard drive and displayed a ? when booting up

    Fortunately, I had documented all these problems with pictures and videos and written a long issue report, which I intended to give to the reseller (in hope of a replacement computer). When the last problem occured, I was very glad that I had taken this step. The support person I gave the computer to doubted that I would get the errors accepted as a reclamation, but when I handed him the report, he said that it improved my chances drastically.

    And so it did…obviously, since I got the computed repaired. After that, it has worked like a charm…

    …until the battery swelled.

    I did not notice it at first, but after a slight bump in the battery, things quickly became worse, and before I knew it, the battery stood out quite a bit from the computer. Apple did NOT accept this complaint, so I had to buy a new battery. Luckily, I found a reseller that sold unofficial batteries.

    Still…(suprised that the problems keep washing over me?)…the new battery did not work as I had hoped. I will write about this in the next entry…the green/orange color toggle problem.

     
  • danielsaidi 2:33 am on January 26, 2010 Permalink | Reply
    Tags: Content, Folder   

    XNA: Load all content files in a folder 

    After playing around with XNA for a little while, I quickly realised how tedious it is to load all content manually, especially if the project uses a lot of images, sounds, textures etc.

    The method below is an extension method that can parse all files within a folder into any content type. The method requires that the specified folder is relative to the Content.RootDirectory folder.

    /// <summary>
    /// Load all content within a certain folder. The function
    /// returns a dictionary where the file name, without type
    /// extension, is the key and the texture object is the value.
    ///
    /// The contentFolder parameter has to be relative to the
    /// game.Content.RootDirectory folder.
    /// </summary>
    /// <typeparam name="T">The content type.</typeparam>
    /// <param name="contentManager">The content manager for which content is to be loaded.</param>
    /// <param name="contentFolder">The game project root folder relative folder path.</param>
    /// <returns>A list of loaded content objects.</returns>
    public static Dictionary<String, T> LoadContent<T>(this ContentManager contentManager, string contentFolder)
    {
       //Load directory info, abort if none
       DirectoryInfo dir = new DirectoryInfo(contentManager.RootDirectory + "\\" + contentFolder);
       if (!dir.Exists)
          throw new DirectoryNotFoundException();
    
       //Init the resulting list
       Dictionary<String, T> result = new Dictionary<String, T>();
    
       //Load all files that matches the file filter
       FileInfo[] files = dir.GetFiles("*.*");
       foreach (FileInfo file in files)
       {
          string key = Path.GetFileNameWithoutExtension(file.Name);
    
          result[key] = contentManager.Load<T>(contentManager.RootDirectory + "/" + contentFolder + "/" + key);
       }
       //Return the result
       return result;
    }

    The function extends the ContentManager class, and can, for instance, be used by the main Game class like this:

    • var textures = Content.LoadContent<Texture2D>("Textures");
    • var models = Content.LoadContent<Model>("Models");
    • var songs = Content.LoadContent<Song>("Songs");
    • ...

    The method returns  a dictionary, so if you want to access the “warrior” model in the models dictionary, you just have to access it as such:

    • var warriorModel = models["warrior"];

    I am having some problems with pasting in code fragments into this blog, so if anyone can give me some tips for good plugins that can be used at wordpress.com, feel free to do so :)

     
  • danielsaidi 6:47 am on January 25, 2010 Permalink | Reply
    Tags: Tutorial   

    Doing first XNA tutorial 

    After having a look at my friend Jens’ small XNA game framework, which really helps you get started developing your XNA games, I still think I’d benefit from reading a tutorial or two. The game project type is quite different from other types of software I usually develop, so I think it’ll be good to actually read something before getting my hands dirty ;)

    So, I will first go through the Microsoft tutorial for getting a small 2D game up and running, with a bouncing sprite:

    http://msdn.microsoft.com/en-us/library/bb203893.aspx

    After that, I will probably do a couple of more tutorials with 3D models and a bit more advanced functionality, before continuing with my “which-I-thoughtwoul-be-quite-easy” game project.

     
  • danielsaidi 6:49 am on January 24, 2010 Permalink | Reply
    Tags:   

    XNA development 

    After a couple of calm months, I have started looking at XNA game development. I will try to create something simple, but do not have a deadline for doing so. This is simply a fun hobby project.

    As usual, I will post code I develop here, but the XNA specific functionality and classes will not be embedded into the .NET Extensions project.

    I will also try to take a look at NDepend, which I received a pro license for a whiiile back. It seems promising, but I really need to sit down with it to get the hang of how to use it best.

     
c
compose new post
j
next post/next comment
k
previous post/previous comment
r
reply
e
edit
o
show/hide comments
t
go to top
l
go to login
h
show/hide help
esc
cancel