objective-c

Learn MacRuby or Objective-C?

Well, my fisrt question was a bit too general so i ll try again and hope this one is better. The way i see it is: Ruby->MacRuby or IronRuby or Rails Obj-c->Mac Development So Ruby has clearly more potential in desktop and web platforms and now with MacRuby, OSX native (and commercial) apps are on the way. If i get it wrong please correc...

NSKeyedUnarchiver chokes when trying to unarchive more than one object

We've got a custom matrix class, and we're attempting to archive and unarchive an NSArray containing four of them. The first seems to get unarchived fine (we can see that initWithCoder is called once), but then the program simply hangs, using 100% CPU. It doesn't continue or output any errors. These are the relevant methods from the matr...

creating iPhone draggable objects

I need to figure out how in the world do I create object instances (an image) and place them on the screen and have it draggable. I know how to draw an image (png) onto the screen, but how do I make it draggable? ...

What's the regular way of assertion in C?

I'm using NSAssert macro for Objective-C assertion, and it's the regular way to do this. But it's not work in C functions. What do I should use for this? ...

How to access the CGColor property of UIColor in CGContextSetFillColorWithColor?

CGContextSetFillColorWithColor(g, [UIColor greyColor].CGColor); I'm trying to follow O'Reilly's iPhone Game Development book on page 73 Chapter 3 but I'm running into a compile error that states error: request for member 'CGColor' in something not a structure or union According to the book's errata page this is an unconfirmed errata ...

iPhone: Navigation Bar button indefinitely links to it's own view.

Hi there, When I navigate from the root view to another view, it works. However, when I want to get back, the navigation button links to itself. This goes on for about 6 taps, until it eventually goes back to the root view. This only occurs on one view, and the rest are working fine. I have no idea what code is causing this, but if yo...

Sporadic EXC_BAD_INSTRUCTION (SIGILL) when in 64 bit mode

For some reason for a low-number of users (say 1 in a few hundred) the application seem to crash when run in 64bit mode on a Snow Leopard 10.6.3 I've attached the stack traces. The crashed seem to be random in com.apple.AppKit at random locations and random moments. Anyone else had any experiences? Using GCC compiler of Xcode 3.2.2 Cr...

Suggestions on how to implement a UI Element to display a long image in iPhone.

I want to display a long image on iPhone. The user can swipe left or right to see difficult parts of the image. I want to spite the long image into different parts... for example, a long long image is 1000* 100; I want to display 100*100 for each time. When the image is loaded, it shows from x:0 to x:100. When user swipe right, it becom...

Organising files and classes in XCode (iPhone application)

It's a generic question and really a newbie one too, so bear with me... I'm playing with some iPhone development, and trying to create a simple "flip type" application. Nothing sophisticated, let's say on the flip side is a short application summary, bit like 'help' and on the main screen is a simple board game, let's say tic-tac-toe or...

What kind of data type is this?

In an class header I have seen something like this: enum { kAudioSessionProperty_PreferredHardwareSampleRate = 'hwsr', // Float64 kAudioSessionProperty_PreferredHardwareIOBufferDuration = 'iobd' // Float32 }; Now I wonder what data type such an kAudioSessionProperty_PreferredHardwareSampleRate actually is? I...

Can I safely use CGFloat to hold Float64 or Float32 values?

I have an CGFloat property and sometimes I get a return value of type Float64 or also of type Float32. Could I store both safely to CGFloat? ...

Can I safely store UInt32 to NSInteger?

Is an NSInteger big enough for UInt32? Or is it even the same thing? ...

Object-C: initWithContentsOfURL returning null

Hey! I'm working on an app that would display a remote html and use local images, so what I'm trying to do is download the HTML of the website and display it as a "local" page, that would have access to images in my bundle. For some reason I can't get initWithContentsOfURL to work. I checked all manuals and examples I could find and it...

Can I safely store UInt32 to NSUInteger?

In the header, it is defined like: #if __LP64__ || (TARGET_OS_EMBEDDED && !TARGET_OS_IPHONE) || TARGET_OS_WIN32 || NS_BUILD_32_LIKE_64 typedef long NSInteger; typedef unsigned long NSUInteger; #else typedef int NSInteger; typedef unsigned int NSUInteger; #endif So does an UInt32 fit without problems into an NSUInteger (an unsigned int...

String contains string in objective-c (iphone)

How can I check if a string (NSString) contains another smaller string? I was hoping for something like: NSString *string = @"hello bla bla"; NSLog(@"%d",[string containsSubstring:@"hello"]); But the closest I could find was: if ([string rangeOfString:@"hello"] == 0) { NSLog(@"sub string doesnt exist"); } else { NSLog(@"exist...

What does the extern keyword mean?

What does the extern keyword mean? I've seen that in front of an function declaration like extern void DoFoo ... ...

Accepting drag operations in an NSCollectionView subclass

I've subclassed NSCollectionView and I'm trying to receive dragged files from the Finder. I'm receiving draggingEntered: and returning an appropriate value, but I'm never receiving prepareForDragOperation: (nor any of the methods after that in the process). Is there something obvious I'm missing here? Code: - (void)awakeFromNib { [...

Collection <NSCFSet: 0x1b0b30> was mutated while being enumerated. How to determine which set?

I'm doing a bunch of core data inserts and after 20k or so inserts with saves every 1-2k I get this error: Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection <NSCFSet: 0x1b0b30> was mutated while being enumerated.' I'm trying to figure out which NSSet is causing this. I've done a search and the onl...

How to show specific area in UIImageView from iPhone?

If I have a image size 1024*768, but I want to show a 100*100 square located on 200, 200. What is the simplest way to do it? Thz u. ...

Clean bindings with structs

I have a model class for which it makes quite a lot of sense to have NSSize and NSPoint instance variables. This is lovely. I'm trying to create an editing interface for this object. I'd like to bind to size.width and whatnot. This, of course, doesn't work. What's the cleanest, most Cocoa-y solution to this problem? Of course I could w...