macOS/iOS API解説

iOS , Mac アプリケーション開発のために使われる主要フレームワークの日本語情報です。2010年代に書かれた内容です。今後更新はありません。

目次

initWithObjects:count:

INDEX>Foundation>NSArray

指定された配列から指定された数のオブジェクトを取り出して配列を初期化します
-(id)initWithObjects:(id *)objects
       count:(NSUInteger)count

解説

objectsで指定された配列からcountで指定された数のオブジェクトを取り出して配列を初期化します。
NSArrayは、初期化された後修正する事は出来ません。
初期化されたオブジェクトは元のオブジェクトと異なっている場合があります。

返り値

( id )

NSArrayまたはそのサブクラス

引数

( id * )objects

配列オブジェクトのポインタ

( NSUInteger )count
( unsigned )count

取り出す数

クラス

NSArray

Instance Methods

使用可能

10.0

参照

- initWithObjects:
+ arrayWithObjects:
- initWithArray:

例文

#import "MyObject.h"

@implementation MyObject

- (IBAction)myAction:(id)sender
{
NSArray *arr1 = [[NSArray alloc] initWithObjects:@"Jan",@"Feb",@"Mar",nil];
NSArray *arr = [[NSArray alloc] initWithObjects:&arr1 count:1];
NSLog([arr description]);
}

@end