常量区字符串(NSString):
initWithFormat (实例方法)
Returns an NSString object initialized by using a given format string as a template into which the remaining argument values are substituted.
- (instancetype)initWithFormat:(NSString *)
format,
...
stringWithFormat(类方法)(转换为字符型)
Returns a string created by using a given format string as a template into which the remaining argument values are substituted.
+ (instancetype)stringWithFormat:(NSString *)
format,,
...
intValue(字符转为整型)(floatValue, doubleValue)
The integer value of the string. (read-only) 啊不错的风格hi就看了么
@property (readonly) int intValue
stringByAppendString(字符串拼接)
Returns a new string made by appending a given string to the receiver.
- (NSString *)stringByAppendingString:(NSString *)
aString
stringByAppendingFormat(字符连接)(参数不同)
Returns a string made by appending to the receiver a string constructed from a given format string and the following arguments.
length(获得字符串长度)
The number of Unicode characters in the receiver. (read-only)
substringToIndex(获取字符串:下标从0开始到给定的下标结束,但不包含给定的下标)
Returns a new string containing the characters of the receiver up to, but not including, the one at a given index.
substringFromIndex(获取字符串:从给定的下标开始到结束,包含给定的下标)
Returns a new string containing the characters of the receiver from the one at a given index to the end.
substringWithRange(获取一定范围内的字符串)
Returns a string object containing the characters of the receiver that lie within a given range.
- (NSString *)substringWithRange:(
NSRange)
aRange
componentsSeparatedByString(给一个字符,把原字符串分割成字符数组)
Returns an array containing substrings from the receiver that have been divided by a given separator.
- (
NSArray *)componentsSeparatedByString:(NSString *)
separator
rangeOfString(子串在原串中的第一次出现的范围,输出开始到结束的下标)`
Finds and returns the range of the first occurrence of a given string within the receiver.
- (
NSRange)rangeOfString:(NSString *)
aString
stringByReplacingOccurrencesOfString:withString:(把字符中所有的某个字符串替换成新的)
Returns a new string in which all occurrences of a target string in the receiver are replaced by another given string.
- (NSString *)stringByReplacingOccurrencesOfString:(NSString *)
target withString:(NSString *)
replacement
hasPrefix:(验证字符串是否以给定的字符串打头)
Returns a Boolean value that indicates whether a given string matches the beginning characters of the receiver.
- (BOOL)hasPrefix:(NSString *)
aString
hasSuffix:(验证字符串是否以给定的字符串结尾)
Returns a Boolean value that indicates whether a given string matches the ending characters of the receiver.
- (BOOL)hasSuffix:(NSString *)
aString
isEqualToString(判断两个字符串的大小,( compare:-1是升序 0是相等 1是降序))
Returns a Boolean value that indicates whether a given string is equal to the receiver using a literal Unicode-based comparison.
- (BOOL)isEqualToString:(NSString *)
aString
lowercaseString(全部字符变成小写)
A lowercase representation of the string.
@property (readonly, copy)
NSString *lowercaseString
uppercaseString(全部字符变成大写)
An uppercase representation of the string. (read-only)
@property (readonly, copy)
NSString *uppercaseString
capitalizedString(字符串的所有的首字符大写)
A capitalized representation of the receiver. (read-only)
@property (readonly, copy)
NSString *capitalizedString
可变字符串(NSMutableString):
appendString:(在原字符串后面添加新字符串)
Adds to the end of the receiver the characters of a given string.
- (void)appendString:(
NSString *)
aString
deleteCharactersInRange:(删除一定范围内的字符串)
Removes from the receiver the characters in a given range.
- (void)deleteCharactersInRange:(
NSRange)
aRange
insertString:atIndex:(在给定的下标位置添加字符串)
Inserts into the receiver the characters of a given string at a given location.
replaceCharactersInRange:withString:(给定一个下标范围,用其他字符串替换范围内的字符串)
Replaces the characters from aRange with those in aString.
- (void)replaceCharactersInRange:(
NSRange)
aRange withString:(
NSString *)
aString
setString(用其他字符串替换掉原字符串)
Replaces the characters of the receiver with those in a given string.
创建数组(NSArray)
initWithObjects:(添加数组元素)
Initializes a newly allocated array by placing in it the objects in the argument list.
- (instancetype)initWithObjects:(id)
firstObj,,...
count(返回数组元素个数)
Returns the number of objects currently in the array.
arrayWithObjects:(类方法添加objects,便利构造器)
Creates and returns an array containing the objects in the argument list.
+ (instancetype)arrayWithObjects:(id)
firstObj,,...
objectAtIndex:(返回给定的下标元素)
Returns the object located at the specified index.
containsObject:(检查一个字符串是否存在数组中)
Returns a Boolean value that indicates whether a given object is present in the array.
- (BOOL)containsObject:(id)
anObject
lastObject(获取数组中最后一个元素) (firstObject)
Returns the last object in the array.
- (id)lastObject
indexOfObject(返回元素在数组内的下标)
Returns the lowest index whose corresponding array value is equal to a given object.
创建一个可变数组(NSMutableArray)
arrayWithCapacity:(每次可以添加几个对象)
Creates and returns an NSMutableArray
object with enough allocated memory to initially hold a given number of objects.
+ (instancetype)arrayWithCapacity:(
NSUInteger)
numItems
addObject:(在数组的末尾添加给定的元素)
Inserts a given object at the end of the array.
- (void)addObject:(id)
anObject
insertObject:atIndex:(在给定的下标处添加元素)
Inserts a given object into the array's contents at a given index.
- (void)insertObject:(id)
anObject atIndex:(
NSUInteger)
index
replaceObjectAtIndex:withObject:(替换给定的下标的元素)
Replaces the object at index with anObject.
- (void)replaceObjectAtIndex:(
NSUInteger)
index withObject:(id)
anObject
exchangeObjectAtIndex:withObjectAtIndex:(两个下标的元素进行交换)
Exchanges the objects in the array at given indices.
removeObjectAtIndex:(移除下标元素)
Removes the object at index .
把基本类型转成对象类型(NSNumber):
(借助NSNumer类,把基本数据类型转成对象类型, 使用时,再把NSumber对象类型转回基本数据类型(intValue))
numberWithInt:(整型)
Creates and returns an NSNumber
object containing a given value, treating it as a signed int
.
+ (NSNumber *)numberWithInt:(int)
value
创建字典型(NSDictionary)
(一个key只能对应一个value, 一个value可以对应多个key, 字典根据key来索引数据)
initWithObjectsAndKeys:(添加多个键值对)
Initializes a newly allocated dictionary with entries constructed from the specified set of values and keys.
- (instancetype)initWithObjectsAndKeys:(id)
firstObject,
, ...
dictionaryWithObjects:forKey:(遍历构造器添加键值对)
Creates and returns a dictionary containing a given key and value.
+ (instancetype)dictionaryWithObject:(id)
anObject forKey:(id<NSCopying>)
aKey
objectForKey:(根据给定键名,查找值)
Returns the value associated with a given key.
- (id)objectForKey:(id)
aKey
allKeys(返回所有的键)
Returns a new array containing the dictionary’s keys.
allValues(返回所有的值)
Returns a new array containing the dictionary’s values.
objectForKey:(返回给定键所对应的值)
Returns the value associated with a given key.
- (id)objectForKey:(id)
aKey
allKeysForObject:(给定值,返回包含值的所有的键)
Returns a new array containing the keys corresponding to all occurrences of a given object in the dictionary.
- (
NSArray *)allKeysForObject:(id)
anObject
创建一个可变字典(NSMutableDictionary)
{
setObject:forKey:(添加一对键值对)
Adds a given key-value pair to the dictionary.
- (void)setObject:(id)
anObject forKey:(id <
NSCopying >)
aKey
setValue:forKey:(键值对)
Invokes setValue:forKey:
on each of the set’s members.
- (void)setValue:(id)
value forKey:(
NSString *)
key
}
现在总结他们2者的区别就是:
1, setObject:forkey:中value是不能够为nil的,不然会报错。
setValue:forKey:中value能够为nil,但是当value为nil的时候,会自动调用removeObject:forKey方法
2, setValue:forKey:中key的参数只能够是NSString类型,而setObject:forKey:的可以是任何类型
removeObjectForKey:(给定键删除相对应的值)
Removes a given key and its associated value from the dictionary.
- (void)removeObjectForKey:(id)
aKey
removeObjectsForKeys:(删除所有的值)
Removes from the dictionary entries specified by elements in a given array.
- (void)removeObjectsForKeys:(
NSArray *)
keyArray
removeAllObjects(删除全部)
Empties the dictionary of its entries.
- (void)removeAllObjects
sortedArrayUsingSelector:(排序)
Returns an array that lists the receiving array’s elements in ascending order, as determined by the comparison method specified by a given selector.
- (NSArray *)sortedArrayUsingSelector:(SEL)
comparator
return NSOrderedAscending(升序排列)
return NSOrderedSame(相等)
return NSOrderedDescending(降序排列)
集合(NSSet)
(集合具有无序性,唯一性和随机取数据)
setWithObjects:(为集合添加对象)
Creates and returns a set containing the objects in a given argument list.
+ (instancetype)setWithObjects:(id)
firstObj,
...
id(通用数据类型)
isKindOfClass:()
Returns a Boolean value that indicates whether the receiver is an instance of given class or an instance of any class that inherits from that class. (required)
- (BOOL)isKindOfClass:(Class)
aClass