Empty string
in iOS applications, if you request data from the network, return JSON or XML format data, often encounter empty string, the general interface is written in Java and other languages, if it is Android, because the source language is Java, just judge whether equals null can, But in iOS there are various forms of each, such as NULL, (NULL),<null>.
If you simply use
Copy Code code as follows:
Unable to determine empty string for Chunchan bracket
Complete Judgment method
Copy Code code as follows:
-(BOOL) IsNull: (ID) object
{
To determine if an empty string
if ([Object Isequal:[nsnull Null]]) {
return NO;
}
else if ([Object Iskindofclass:[nsnull class]])
{
return NO;
}
else if (Object==nil) {
return NO;
}
return YES;
}
Sending a message to an empty string can be a different kind of crash, very silent, and the same. converting strings
Copy Code code as follows:
-(nsstring*) Convertnull: (ID) object{
Convert empty string
if ([Object Isequal:[nsnull Null]]) {
return @ "";
}
else if ([Object Iskindofclass:[nsnull class]])
{
return @ "";
}
else if (Object==nil) {
return @ "None";
}
return object;
}
page pass values and custom copies
When doing some network-related problems, sometimes the value is more, custom a class, want to pass the entire part of the class value to another interface, which involves copying the problem, the custom class must implement the Nscopying protocol, write the method of copying-(ID) Copywithzone: ( Nszone *) zone, so that this class will be the same as the NSString class, you can use = Assignment copy.
Customizing a Typesitem class, inheriting from NSObject, containing three variables (customizable to add multiple)
TypesItem.h
Copy Code code as follows:
#import <Foundation/Foundation.h>
@interface typesitem:nsobject<nscopying>
{
NSString *type_id;
NSString *type_memo;
NSString *type_name;
}
@property (nonatomic,copy) NSString *type_id;
@property (nonatomic,copy) NSString *type_memo;
@property (nonatomic,copy) NSString *type_name;
@end
TYPESITEM.M file, in addition to synthesize these three variables
Copy Code code as follows:
@synthesize Type_id,type_memo,type_name;
Also implement the Nscopying protocol method
Copy Code code as follows:
-(ID) Copywithzone: (Nszone *) zone
-(ID) Copywithzone: (Nszone *) zone
{
Typesitem *newitem = [[Typesitem allocwithzone:zone] init];
Newitem.type_name = Self.type_name;
newitem.type_id = self.type_id;
Newitem.type_memo = Self.type_memo;
return newitem;
}
Values are passed between pages, assuming that the value of the Typeitem in the A->b,a is passed to B
Write code in the. h file in B
Copy Code code as follows:
@property (nonatomic,copy) Typesitem *selecteditem;
In the B.M file
Copy Code code as follows:
@synthesize SelectedItem;
Add code before jumping to B in a.m
Copy Code code as follows:
Bviewcontroller *BVC = [[[Bviewcontroller alloc] initwithnibname:@ "Bviewcontroller" Bundle:nil] autorelease];
Item is a typeitem type and is not empty
Bvc.selecteditem = Item;
[Self.navigationcontroller PUSHVIEWCONTROLLER:BVC Animated:yes];
PS: When the values are passed between pages, the BVC in the Bvc.selecteditem must be in line with the push-past BVC, otherwise the SelectedItem value in the push to B interface must be null.