常用API

常量区字符串(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.
- (void)insertString:( NSString *) aString atIndex:( NSUInteger) anIndex

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.

- (void)setString:( NSString *) aString

创建数组(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.

- ( NSUInteger)count

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.

- (id)objectAtIndex:( NSUInteger) 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.

- ( NSUInteger)indexOfObject:(id) anObject

创建一个可变数组(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.

- (void)exchangeObjectAtIndex:( NSUInteger) idx1 withObjectAtIndex:( NSUInteger) idx2

removeObjectAtIndex:(移除下标元素)

Removes the object at index .

- (void)removeObjectAtIndex:( NSUInteger) 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.

- ( NSArray *)allKeys

allValues(返回所有的值)

Returns a new array containing the dictionary’s values.

- ( NSArray *)allValues

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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
CompletableFuture是Java 8中引入的一个类,用于支持异步编程和并发操作。它提供了丰富的API来处理异步任务的结果和操作。以下是CompletableFuture的一些常用API: 1. `CompletableFuture.supplyAsync(Supplier<U> supplier)`:创建一个CompletableFuture对象,该对象会在异步执行给定的Supplier任务后返回结果。 2. `CompletableFuture.runAsync(Runnable runnable)`:创建一个CompletableFuture对象,该对象会在异步执行给定的Runnable任务后返回结果。 3. `CompletableFuture.thenApply(Function<? super T,? extends U> fn)`:对CompletableFuture的结果应用给定的函数,并返回一个新的CompletableFuture对象。 4. `CompletableFuture.thenAccept(Consumer<? super T> action)`:对CompletableFuture的结果应用给定的消费者函数,不返回任何结果。 5. `CompletableFuture.thenRun(Runnable action)`:在CompletableFuture完成后执行给定的Runnable任务。 6. `CompletableFuture.thenCombine(CompletionStage<? extends U> other, BiFunction<? super T,? super U,? extends V> fn)`:将两个CompletableFuture的结果进行组合,并将结果应用给定的函数。 7. `CompletableFuture.thenCompose(Function<? super T,? extends CompletionStage<U>> fn)`:对CompletableFuture的结果应用给定的函数,并返回一个新的CompletableFuture对象。 8. `CompletableFuture.exceptionally(Function<Throwable,? extends T> fn)`:在CompletableFuture发生异常时,应用给定的函数处理异常,并返回一个新的CompletableFuture对象。 9. `CompletableFuture.whenComplete(BiConsumer<? super T,? super Throwable> action)`:在CompletableFuture完成后,应用给定的函数处理结果或异常。 10. `CompletableFuture.allOf(CompletableFuture<?>... cfs)`:返回一个CompletableFuture对象,该对象在所有给定的CompletableFuture对象都完成后完成。 以上是CompletableFuture的一些常用API,你可以根据具体的需求选择适合的方法来处理异步任务。如果你有具体的问题或需要更多的示例,请告诉我。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值