Category Archives: xcode

Using Objective-C in Swift projects with a bridging-header

A general problem with starting a new project in a new language is that most of the times you are missing the libraries, classes etc. you feel comfortable with.

Same happens with making the switch from Objective-C to Swift.

But there is a solution that is called “bridging header”, that brings Objective-C into Swift.

Using it , its not that complicated.

  1. create a .h file in your project, e.g. projectname-bridging-header.h
  2. open the Build Settings in your project targets and search for “bridging
  3. add your filename (here: projectname-bridging-header.h) to the “Objective-C Bridging Header” including the path the file can be found (e.g. projectname/projectname-bridging-header.h)
  4. open your projectname-bridging-header.h and add your import lines as you would do in a normal Objective-C header (e.g. #import “foo.h”)

That’s it.

Now you can access and use the new available classes in the Swift way.

Create dynamic height for UITableViewCells in iOS

During my try creating a forum view with threads and posts for ios devices i figured out that there is no option to get an automatic height for table cells if the content is larger then the layout i created in the .xib file.

After not finding a proper and easy solution in several developer forum, it took me some days to figure out a way to get it done in a way that seems to work for me.
Calculating the size of the content seems to do the trick.

In my layout i have label for the username, a label for the date of the post and the message itself.
post_layout
The message label is the only content, that could cause any issues, so this is the only part that needs to be calculated.

Here is the code that does it for me:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSObject *Thread = [_postArray objectAtIndex:indexPath.row];
    NSString *message =[Thread valueForKeyPath:@"Forum.message"];
    CGSize maximumLabelSize = CGSizeMake(296,9999);
    UIFont *font = [UIFont systemFontOfSize:17];
    CGSize expectedLabelSize = [message sizeWithFont:font constrainedToSize:maximumLabelSize lineBreakMode:NSLineBreakByWordWrapping];
    int a = expectedLabelSize.height + 55;
    return a;
}

Note:
– you can get systemFontSize also through a function, so it could be dynamic
– 55 is the fix height of the content above the message label

If there are other – maybe better or more comfortable – ways, please let me know. 🙂

Using Doxygen in Xcode

This is just a quick recommendation to a blog post from my friend Oliver, writing about how to implement Doxygen in Xcode and automate it.

If you develop your software in groups, create a framework, or just want to show your latest development project to other people, your want documentation for your code. For Objective-C in Xcode projects there are solutions like HeaderDoc or AutoDoc, but the lack of solid documentation seems almost ironic. So I found doxygen, which has better documentation and supports multiple platforms, multiple programming languages, and multiple output formats.

Read the very helpful post at http://www.geek-nation.de/2012/12/doxygen-in-xcode-4/