Today I released the second public version of my new library PHPTypeSafe. It is now compatible with the current version of PHP 5.3 (right now it is RC2). I think we won't see any major changes with the namespace handling in PHP 5.3 anymore, so I felt I could upgrade the library.

One mayor move is the hosting of the source. I moved the sources from my own public subversion repository to GitHub, as the library is Open Source and may be improved more easily when using git.

PHPTypeSafe still provides the ability to use PHPs Type Hinting feature for scalar values.

So what does PHPTypeHint offer?

By including PHPTypeSafe in your project you will be able to use Parameter Type Hinting for scalar values and the special type resource. A simple example on how to use this functionality would be:

The output would be:

PHPTypeSafe offers the support for the following types:

  • boolean (including alias bool)
  • float (including aliases double and real)
  • integer (including aliases int and long)
  • resource
  • string

Every type hint matcher is strict (so '1' won't match with the integer type hint), as you shouldn't use type hints if you aren't sure about the given /required type of value. (Those cases could still be checked using is_string(), is_int() and the like.)

You can get PHPTypeSafe RC2 via git at GitHub or download the PHAR archive at GitHub.

A few days ago I had a weird issue with comparing NSArrays via isEqualToArray. isEqualToArray must be used for NSArrays, as isEqual doesn't work (because the isEqual method only returns YES if the compared objects actually the same object).

The problem I had was, that I was comparing two arrays in my Unit Tests - one NSArray constructed via the method I was testing and the other as the NSArray to test against. One thing to note is, that both NSArrays contained a few NSDictionaries.

With a lot of googling and more looking into it, it seems isEqualToArray fails because isEqual fails if comparing an immutable and mutable dictionary. If both NSDictionarys are immutable, then isEqual succeeds. I have no idea why isEqual fails if the mutability is different, but the contents are identical.

Conclusion: remember to make sure, that the contents of the NSArrays have the same (im)mutability. That's all ;) ...

A few days ago I blogged about the release of the studiVZ iPhone App to the Apple App Store.

Since today you can also get iPhone apps for the other two platforms of studiVZ Ltd.: the meinVZ App and the schuelerVZ App.

The link to the studiVZ iPhone App:
http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=300414974&mt=8

The link to the meinVZ iPhone App:
http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=305981067&mt=8

The link to the schuelerVZ iPhone App:
http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=306111737&mt=8

A few days ago I blogged about Apple should be approving the studiVZ iPhone App very soon ... since today you can get the application yourself, as Apple released the app.

The link to the iPhone app:
http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=300414974&mt=8

studiVZ for iPhone ... coming soon!

| | Comments (0) | TrackBacks (2)

We're just waiting for the App Store approval ...






studiVZ iPhone App 1studiVZ iPhone App 2

studiVZ iPhone App 3studiVZ iPhone App 4

I recently found out, that even though according to the documentation sizeToFit on a UILabel will take into account the numberOfLines property, it simply doesn't.

You have seen variable heights of UITableViewCell in iPhone applications like App Store, Address Book, SMS and so on. These applications have a UITableView as main part, but each cell in the table has a variable height according to text amount it holds.

With UITableView it is quite different if you're coming from a HTML world, as UITableView cannot generate a dynamic height automatically, you'll need to calculate the height yourself before you set the delegate.

How to make UILabel / UITableViewCell to have a dynamic height

After you created a UITableView, you will need to set a delegate and a datasource. There is a UITableViewDelegate method to tell UITableView how tall a cell would be:

If you want UITableViewCell to have a dynmic height, you'll need to calculate the height of text block and return the result in the method I mentioned above.

There are four NSString methods that can do the calculations:

To calculate the exact height of a text block, you'll need to specify a large CGSize and those methods will return you exact size, here's an example:

Then you can get the height by accessing aSize.height.

What I'm doing most of the time is to call one of those methods in the model class when setting the string and storing the height in the model class, so you can use the correct height right away.

Now to size the UILabel and/or UITableViewCell you just need to set the frame property of UILabel and/or UITableViewCell.

With iPhone SDK 2.2 and the iPhone OS 2.2 update localizations other than English do not work on a real device for a lot of developers. Testing on the iPhone simulator, all seems to work fine.

First the explanation

In my case I noticed that the english files were UTF-16 (apparently created by a XCode project template), but the localizations were UTF-8 (created by make file localizable command).

When handling some UTF-8 strings files (it seems to depend of the first 3 bytes), copystrings (the ruby script that copies Localization files) creates a temporary file which is a slightly modified copy of the input file. It then does the job as if this temporary file was the input file. Incidentally, it forgets to keep the old name of the output file instead of the new including the pid of the copystrings process.

The simple workaround

Disclaimer: Before doing that, make a copy of your project; we never now what can happen when converting a file format.

  • Don't use UTF-8 encoded files for localization strings file currently.
  • To change the encoding with XCode, select the whole content, ...
  • ... then go to View -> Text -> File Encoding -> UTF-16 (any of those will work).
  • And then chose Convert.

Any other good text editor has probably a similar way of changing the file format.

Important:

Clean all targets and re-build. It should work. It worked for me and the bug in the script seems only to concern some UTF-8 files.

Recent Activity

Tuesday

  • I tweeted, "Björn S. hat fertig! Und das schon um 20 Uhr ... *g*"
Sunday

  • I tweeted, "@shiflett Choose Tweetie ... that's the app I now prefer. You'll like it!"
  • I tweeted, "I just blogged about: "Type Hints for scalar values - PHPTypeSafe now compatible with current PHP 5.3". #php #phptypesafe http://is.gd/CWF3"

More ...

Conferences

Conferences I presented at:

Programming Blogs - BlogCatalog Blog Directory
Creative Commons License
This weblog is licensed under a Creative Commons License. blogoscoop

Find recent content on the main index or look in the archives to find all content.