Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

saleh.hi.62

macrumors member
Original poster
Jul 25, 2011
95
0
Hello guys,

I need to create new data type with a NSDictionary and then when i declare the object be able to work with that with its functions ,look at this code

this code is doing what i want

.h file
Complete code
Code:
@interface TFHppleElement : NSObject {
@private
  
  NSDictionary * node;
  TFHppleElement *parent;
}

.m file
Complete Code
Code:
@interface TFHppleElement ()
@property (nonatomic, retain, readwrite) TFHppleElement *parent;
@end

@implementation TFHppleElement
@synthesize parent;

and for using it's like this:

Code:
TFHppleElement * element = [elements objectAtIndex:0];
here it is assigning an NSDictionary which is a the forst element of array.

i wanna know how i can make a data type like this and what it is called?
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
I really can't tell what you want here. What type is elements? And what does that snippet have to do with your goal? You can put any NSObject in an NSArray.

Are you wanting to pass messages that are passed to a TFHppleElement to be passed through to its NSDictionary ivar? You can do it with this:
http://developer.apple.com/library/...ObjCRuntimeGuide/Articles/ocrtForwarding.html

You can override forwardInvocation:, ask your NSDictionary if it responds to the message with respondsToSelector:... if so pass it on, if not call the super implementation.

If your intent is different explain it more clearly.

-Lee
 

saleh.hi.62

macrumors member
Original poster
Jul 25, 2011
95
0
Sometimes I wonder if your posts are trolling.

Umm... a linked list that is optimized for being traversed in reverse direction?

No, that was all an example, i just want to make 1 like this
Code:
TFHppleElement * element = [elements objectAtIndex:0];

TFHppleElement here appeared as a object that receive a NSDictionary, the matter is how can i design like that for my own matter?
 

admanimal

macrumors 68040
Apr 22, 2005
3,531
2
I don't even think you understand what this code
Code:
TFHppleElement * element = [elements objectAtIndex:0];
actually does. All it is doing is getting one instance of TFHppleElement from an array of such elements. It has nothing to do with NSDictionary.

Why don't you tell us, without mentioning TFHppleElement at all, what you are trying to do.
 

subsonix

macrumors 68040
Feb 2, 2008
3,551
79
You could make a dictionary of dictionaries, instead of making a wrapper around NSDictionary. If you want to link several of these objects you will need to create methods that take care of the linking, allocation, traversal of the data structure as well as unlinking and releasing of the internal objects.
 

saleh.hi.62

macrumors member
Original poster
Jul 25, 2011
95
0
ok i just wrote what i had in mind

.h file

Code:
@interface ICItem : NSObject
{
	NSMutableDictionary *Item;
	
}
@property (assign)NSMutableDictionary *Item;

-(void)setFieldAndValue:(NSString*)field:(NSString*)value;
-(NSString*)getValueForField:(NSString*)field;
-(NSArray*)allfields;
-(NSArray*)allvalues;
-(void)delElementFromItem:(NSString*)field;


@end

.m file

Code:
@implementation ICItem
@synthesize item;

-(id)init{
if (self=[super init]) {
	item=[NSMutableDictionary dictionary];
	
	}
	return self;
}
-(void)setFieldAndValue:(NSString*)field:(NSString*)value{

	[item setObject:value forKey:field];

}
-(NSString*)getValueForField:(NSString*)field{
	return [item objectForKey:field];

}

-(NSArray*)allfields{
	
	return [item allKeys];
}

-(NSArray*)allvalues{
	
	return [item allValues];
}

-(void)delElementFromItem:(NSString*)field{
	
	[item removeObjectForKey:field];

}


@end



what i want to do is to do :
NSMutableDictionary *ns=[[NSMutableDictionary alloc] init];
[ns setObject:mad:"saleh" forKey:mad:"name"];
[ns setObject:mad:"student" forKey:mad:"occupation"];

ICItem *item=ns;

[ns allfields];
this is the operation that i would like to implement.
 

gnasher729

Suspended
Nov 25, 2005
17,980
5,565
Code:
-(id)init{
if (self=[super init]) {
	item=[NSMutableDictionary dictionary];
	
	}
	return self;
}[/QUOTE]

I noticed that either you set the warning levels in your compiler very low, or you are ignoring warnings. Both are very bad. The compiler can give you valuable information. Almost every single time that the compiler gives me a warning it turns out to be a bug that I fix within five seconds instead of wasting hours finding it. 

At previous times, people told you how to find problems and you wouldn't believe that they knew what the problem was. Look carefully at the code that I quoted and try to figure out how I know that you don't get warnings or ignore them. Then you should really spend an hour to find out how to get warnings from the compiler, and then remove all warnings from your code.

Oh my god. I had seen the thing that should give a warning. But there is also a really big bummer in your code that will crash it very soon. [B]Learn about memory management[/B]. [B]Learn how to use that static analyzer[/B]. There is a [B]huge bug[/B] in your code, and if you spent the time setting up XCode properly it would tell you about it as soon as you build your code. You are too ignorant to learn your tools, and waste ten times more time finding problems than it would cost you to [B]learn your tools[/B].

By the way: My company is outsourcing some projects. From your posts I conclude that you are not involved in one of those projects, and believe me, I would know. And believe me, if you were involved in one of those projects, my manager's manager would be talking to your manager's manager and would be asking what the hell is going on.
 
Last edited:

saleh.hi.62

macrumors member
Original poster
Jul 25, 2011
95
0
I noticed that either you set the warning levels in your compiler very low, or you are ignoring warnings. Both are very bad. The compiler can give you valuable information. Almost every single time that the compiler gives me a warning it turns out to be a bug that I fix within five seconds instead of wasting hours finding it.

At previous times, people told you how to find problems and you wouldn't believe that they knew what the problem was. Look carefully at the code that I quoted and try to figure out how I know that you don't get warnings or ignore them. Then you should really spend an hour to find out how to get warnings from the compiler, and then remove all warnings from your code.

Oh my god. I had seen the thing that should give a warning. But there is also a really big bummer in your code that will crash it very soon. Learn about memory management. Learn how to use that static analyzer. There is a huge bug in your code, and if you spent the time setting up XCode properly it would tell you about it as soon as you build your code. You are too ignorant to learn your tools, and waste ten times more time finding problems than it would cost you to learn your tools.

By the way: My company is outsourcing some projects. From your posts I conclude that you are not involved in one of those projects, and believe me, I would know. And believe me, if you were involved in one of those projects, my manager's manager would be talking to your manager's manager and would be asking what the hell is going on.

:eek:
 

admanimal

macrumors 68040
Apr 22, 2005
3,531
2
Aside from the bug that gnasher pointed out, what is the point of wrapping the NSDictionary in another class? You aren't adding any functionality to it at all. Do you plan to add more data or methods to that class?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.