Advertise Books Events Forum News Social Networking Support Us

sdkIQ for iPhone
($4.99)

Shape Up
($0.99)

Your First iPhone App
($1.99)

iVidCam Free
(free)

Kid Art
($0.99)

iPUBQUIZ
(£1.19)

ArtStudio
($3.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 07-02-2009, 10:00 AM   #1 (permalink)
Jonnebob
New Member
 
Join Date: Jul 2009
Posts: 3
Question Casting and Obj-C

Is casting a bad thing? What are peoples thoughts on the matter? Should it be avoided where possible? or a necessary evil?

The reason I ask is that i'm following the Stanford lectures and working my way through the assignments and on the first one they ask you to make an NSDictionary and only print out the values from entries into the dictionary which have a key with a certain prefix.

Thats fine I thought as I wrote my first verision of the for loop:

Code:
for (NSDictionary *entry in bookmarkDict)
		
	{
		if ([entry hasPrefix:@"Stanford"]) 
		{
			NSLog(@"Key: '%@' URL: '%@'", entry, [bookmarkDict objectForKey:entry]);
		}
		
	}
Without using the Cast I get an warning: "warning: 'NSDictionary' may not respond to '-hasPrefix:'"

Whats the problem you may be thinking? A Simple cast and the warning dissappears! Well me being the perfectionist I would quite like my finished solution (and for future reference too) to have no cast, if possible.

So, have I missed a method name somewhere in the documentation or is this a case where a cast is the only solution?
Jonnebob is offline   Reply With Quote
 
Enter the iPhone App Challenge!  Win $500!
» Advertisements
» Stats
Members: 24,264
Threads: 39,062
Posts: 171,295
Top Poster: smasher (2,575)
Welcome to our newest member, jessejames
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 07:38 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.