XML DTD parsing - foundElementDeclarationWithName: not passing any value in model - nsxmlparser

For a DTD such as below, NSXMLParser does not seem to be returning anything in the model argument of foundElementDeclarationWithName. What am I missing here?
DTD -
<!DOCTYPE note [ <!ELEMENT note (to,heading)><!ELEMENT to (#PCDATA)><!ELEMENT heading (#PCDATA)>]>
NSXMLParserDelegate method -
- (void)parser:(NSXMLParser *)parser foundElementDeclarationWithName:(NSString *)elementName model:(NSString *)model
{NSLog(#"Element - %#, Model - %#", elementName, model);}
Output -
2014-05-18 12:55:39.730 TestNSXMLParser[2146:303] Element - note Model -
2014-05-18 12:55:39.730 TestNSXMLParser[2146:303] Element - to Model -
2014-05-18 12:55:39.731 TestNSXMLParser[2146:303] Element - heading Model -
Why is no value being passed in the model argument? I would have expected the list of sub-elements, etc. found in every !ELEMENT declaration to be there.

Related

What is the meaning of following syntax? (objective-c style method call)

I'm a noob in objective-c (from C#/Java background), and have difficulty understanding following objective-c syntax, which is used in Picker View control(and also other methods we need to implement for using Picker View):
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row
forComponent:(NSInteger)component
In order to understand, I tried to map it to the following syntax, but seems to be totally different.
-(NSString *)MethodName: (UIPickerView *)FirstParam and:(NSInteger)SecondParam
and:(NSInteger)ThirdParam
Could someone decompose the parts and give some explanation please?
It's a method named
pickerView:titleForRow:forComponent:
It returns a pointer to a NSString, and requires parameters of types UIPickerView*, NSInteger, and NSInteger.
A java-like method declaration might look like this:
NSString pickerViewTitleForRowForComponent(UIPickerView pickerView, NSInteger row, NSInteger component)
The difference is that in Objective-C the method name is composed of parts, and not a single string as in java.
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row ...
/* ^ ^ ^ ^ ^
| | | | |
Return Type | Argument Type | 2nd part of m. name etc....
| |
Part of method name Argument Name
*/
...erik aligner and bdares answers explain all
just one more thing:
the "-" minus letter at the beginning means that you can call this method with an instance of the class.
in this case the method is called by the pickerView itself (you don't call it, you just implement it in a class which adopts the UIPickerViewDelegate Protocol / meaning it use all methods required by that protocol )
but, in general, methods that start with minus sign should be called on instances.
for example, the method
- (void)addSubview:(UIView *)view
declared in UIViewClass, should be called this way:
[yourUIViewInstance addSubview:yourSubViewInstance];
while methods declared with a plus "+" sign mean that you need to call them not on instance (you may have not any instance allocated at all) but on the class itself
for example, for UIView method
+ (void)setAnimationDelay:(NSTimeInterval)delay
you should call it this way:
[UIView setAnimationDelay:1.0];
The method name (selector) is all three components: pickerView:titleForRow:forComponent:. Aside from that, you have it exactly right. (Yes, arguments and selector segments are mixed together in Objective-C. This is one of its strengths; it aids readability of long message expressions.)

Error in function call

I have the following function:
-(void) CalLevels: (NSMutableArray *)rPrices: (NSMutableDictionary *) rLevels: (float) nClose: (float) nHigh: (float) nLow: (float) nOpen {...}
I am calling the above function as follows:
[self CalLevels:rm.rPrices rLevels:rm.rLevels nClose:nCloseD nHigh:nHighD nLow:nLowD nOpen:nOpenD];
I get the warning method not found. Thanks for any help.
You should call it like that:
[self CalLevels:rm.rPrices :rm.rLevels :nCloseD :nHighD :nLowD :nOpenD];
or change the method declaration, since rLevel and its friends are the internal method name of the variables, not part of the method name.
The correct way is either the one above, or change the method signature:
-(void) CalLevels: (NSMutableArray *)rPrices rLevels: (NSMutableDictionary *) rLevels nClose: (float) nClose nHigh: (float) nHigh nLow: (float) nLow nOpen : (float) nOpen {...}
Your method declaration is busted. You write:
-(void) CalLevels: (NSMutableArray *)rPrices: (NSMutableDictionary *) rLevels: (float) nClose: (float) nHigh: (float) nLow: (float) nOpen
This declares a method named CalLevels::::::. The rLevels, nClose and all that are parsed as the parameters' names. You probably meant to declare one named alLevels:rPrices:rLevels:nClose:nHigh:nLow:nOpen:. That would look more like this:
- (void)CalLevels:(NSMutableArray *)levels rPrices:(NSMutableDictionary *)rPrices rLevels:(float)rLevels nClose:(float)nClose nHigh:(float)nHigh nLow:(float)nLow nOpen:(float)nOpen
(I'm guessing that nOpen is meant to be a float.)
What #MByD wrote will work but if you want to adhere to the Naming Conventions you need to rename your method. Right now your method is named CalLevels:::::: and rLevels, nClose, etc. are the parameter names that are not part of the name. If you want to follow the Naming Conventions, you need to:
Start the name with a lowercase letter. CalLevels... is wrong, calLevels... is right.
Use keywords before all arguments. calLevels:::::: is wrong, calLevels:rPrices:rLevels:nClose:nHigh:nLow:nOpen: is right.
Resulting in something like this:
-(void)calLevels:(NSMutableArray *)rLevels rPrices:(NSMutableDictionary *)rPrices nClose:(float)nClose nHigh:(float)nHigh nLow:(float)nLow nOpen:(float)nOpen;

Is there an tutorial that shows how attribute validation works in Core Data?

I'd like to play around with attribute value validation, but the documentation is pretty empty on this. Maybe there's an good article or tutorial out there?
Here is a fairly common validation to ensure you don't get nonsensical dates put into a timeStamp.
- (BOOL)validateTimeStamp:(id *)valueRef error:(NSError **)outError
{
NSDate *testDate=(NSDate *) valueRef;
if ([testDate compare:self.minimumTimeStamp]==NSOrderedAscending) {
// generate and return error so you can set a proper date
}
return YES;
}

iPhone SDK / Objective C Syntax Question

To all,
I was looking at the sample project from http://iphoneonrails.com/ and I saw they took the NSObject class and added methods to it for the SOAP calls.
Their sample project can be downloaded from here http://iphoneonrails.com/downloads/objective_resource-1.01.zip.
My question is related to my lack of knowledge on the following syntax as I haven't seen it yet in a iPhone project.
There is a header file called NSObject+ObjectiveResource.h where they declare and change NSObject to have extra methods for this project. Is the "+ObjectiveResource.h" in the name there a special syntax or is that just the naming convention of the developers.
Finally inside the class NSObject we have the following
#import <Foundation/Foundation.h>
#interface NSObject (ObjectiveResource)
// Response Formats
typedef enum {
XmlResponse = 0,
JSONResponse,
} ORSResponseFormat;
// Resource configuration
+ (NSString *)getRemoteSite;
+ (void)setRemoteSite:(NSString*)siteURL;
+ (NSString *)getRemoteUser;
+ (void)setRemoteUser:(NSString *)user;
+ (NSString *)getRemotePassword;
+ (void)setRemotePassword:(NSString *)password;
+ (SEL)getRemoteParseDataMethod;
+ (void)setRemoteParseDataMethod:(SEL)parseMethod;
+ (SEL) getRemoteSerializeMethod;
+ (void) setRemoteSerializeMethod:(SEL)serializeMethod;
+ (NSString *)getRemoteProtocolExtension;
+ (void)setRemoteProtocolExtension:(NSString *)protocolExtension;
+ (void)setRemoteResponseType:(ORSResponseFormat) format;
+ (ORSResponseFormat)getRemoteResponseType;
// Finders
+ (NSArray *)findAllRemote;
+ (NSArray *)findAllRemoteWithResponse:(NSError **)aError;
+ (id)findRemote:(NSString *)elementId;
+ (id)findRemote:(NSString *)elementId withResponse:(NSError **)aError;
// URL construction accessors
+ (NSString *)getRemoteElementName;
+ (NSString *)getRemoteCollectionName;
+ (NSString *)getRemoteElementPath:(NSString *)elementId;
+ (NSString *)getRemoteCollectionPath;
+ (NSString *)getRemoteCollectionPathWithParameters:(NSDictionary *)parameters;
+ (NSString *)populateRemotePath:(NSString *)path withParameters:(NSDictionary *)parameters;
// Instance-specific methods
- (id)getRemoteId;
- (void)setRemoteId:(id)orsId;
- (NSString *)getRemoteClassIdName;
- (BOOL)createRemote;
- (BOOL)createRemoteWithResponse:(NSError **)aError;
- (BOOL)createRemoteWithParameters:(NSDictionary *)parameters;
- (BOOL)createRemoteWithParameters:(NSDictionary *)parameters andResponse:(NSError **)aError;
- (BOOL)destroyRemote;
- (BOOL)destroyRemoteWithResponse:(NSError **)aError;
- (BOOL)updateRemote;
- (BOOL)updateRemoteWithResponse:(NSError **)aError;
- (BOOL)saveRemote;
- (BOOL)saveRemoteWithResponse:(NSError **)aError;
- (BOOL)createRemoteAtPath:(NSString *)path withResponse:(NSError **)aError;
- (BOOL)updateRemoteAtPath:(NSString *)path withResponse:(NSError **)aError;
- (BOOL)destroyRemoteAtPath:(NSString *)path withResponse:(NSError **)aError;
// Instance helpers for getting at commonly used class-level values
- (NSString *)getRemoteCollectionPath;
- (NSString *)convertToRemoteExpectedType;
//Equality test for remote enabled objects based on class name and remote id
- (BOOL)isEqualToRemote:(id)anObject;
- (NSUInteger)hashForRemote;
#end
What is the "ObjectiveResource" in the () mean for NSObject? What is that telling Xcode and the compiler about what is happening..?
After that things look normal to me as they have various static and instance methods. I know that by doing this all user classes that inherit from NSObject now have all the extra methods for this project.
My question is what is the parenthesis are doing after the NSObject. Is that referencing a header file, or is that letting the compiler know that this class is being over ridden.
Thanks again and my apologies ahead of time if this is a dumb question but just trying to learn what I lack.
This is a Category. It allows you to extend an existing class. Instead of
MyClass : MySuperclass
it's declared via:
MyClass (MyCategoryName)
The name of the file is simply a convention MyClass+MyCategory.h. The filename makes no real difference, but this makes it easy to tell the file contains a category of methods that extends a specific class.
Note that you can implement new methods in a category, but you cannot add instance variables. And to use a category elsewhere in your codebase, all you must do is import the category header and all methods it contains will be made available on the objects the category extends.
This is called a "category" in Objective-C. See the "Categories and Extensions" chapter of The Objective-C Programming Language for more information.
The +ObjectiveResource.h thing is just a common convention for naming files that contain categories. It doesn't have any significance to the compiler.
The first two answers are correct - it's a Category, which is a way to extend the functionality of an existing class.
It's a really powerful feature in Objective-C, but it can be abused too. It can be dangerous to put Categories on low-level classes like NSObject, unless you know exactly what the implications are. For example, if you add methods to NSObject, you are essentially adding the methods to any class that inherits from NSObject, which is pretty much everything. Note that you can only utilize the category methods if you include the header, but it can still produce unexpected results in some cases.

NSArray question - \n\t\t being added to the end of strings?

My strings are fine, but when they get added to an array a weird grouping of "\n\t\t" gets added to the end. So the string "Apple", becomes "Apple\n\t\t" when I look at the array description.
Whats the deal with that? and how do I fix it?
Addition:
Its XML code. It seemed like [currentPlace appendString:string]; would get the right part, then add the \n\t\t next time round. I solved this by alternating using a boolean:
if (alternate == NO) {
[currentPlace appendString:string];
alternate = YES;
} else {
alternate = NO;
}
Is there a better way to alternate? I remember there being a case + break way, but I forget how to do it.
Adding strings to an array obviously does not modify their contents. Your bug is somewhere else, a part of your program you did not describe. Without code, nobody would be able to help you.
I solved this by adding a switch to:
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string;
All is good now.