Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 07-02-2009, 11: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
 

» Advertisements
» Stats
Members: 158,672
Threads: 89,155
Posts: 380,385
Top Poster: BrianSlick (7,110)
Welcome to our newest member, JMadisonT2012
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 05:41 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.