initWithUUIDString:
initWithUUIDBytes:
-localizedNameOfStringEncoding:
現在の言語のエンコーディングの名前を返す
+(NSString *)localizedNameOfStringEncoding:(NSStringEncoding)encoding
- 出版社/メーカー: 六花亭
- メディア: その他
- この商品を含むブログを見る
解説
現在の言語のエンコーディングの名前を返します
返り値
( NSString * )
エンコーディングの名前
引数
( NSStringEncoding )encoding
エンコーディング
フレームワーク
Foundation
クラス
NSString
使用可能
10.0
参照
例文
[NSString localizedNameOfStringEncoding:documentEncoding] // NSString *str1 = [NSString stringWithString:@"12345"]; [info setStringValue:[NSString localizedNameOfStringEncoding:[NSString availableStringEncodings]]];
NSLog
ログを表示する
void NSLog (
NSString * format ,
... ... );
解説
ログを表示する
void NSLog(NSString *format, ...)
●__LINE__で行数を表示
NSLog(@"%d: failed", __LINE__);
●__PRETTY_FUNCTION__で関数またはメソッドを表示
●__FILE__でファイル名を表示(フルパス)
【format】
● %@ 文字
●%% '%' 文字
●%zd NSInteger型
●%d, %D, %i 符号あり32ビット整数数値 (long)
● %d intを符号付き10進数で表示
●%04d 4桁の符号あり32ビット整数数値、不足の桁は0で補う
●%ld
● %o intを符号付き8進数で表示
●%o, %O 32ビット整数数値(unsigned long)
● %u intを符号なし10進数で表示
●%qi 符号あり64ビット整数数値(long long)
●%qu 符号なし64ビット整数数値(unsigned long long)
●%qx 符号なし64ビット整数数値(unsigned long long)。0-9とa-fで表記
●%qX 符号なし64ビット整数数値(unsigned long long)。0-9とA-Fで表記
●%u, %U 符号なし32ビット整数数値r (unsigned long)
●%hi 符号あり16ビット整数数値 (short)
●%hu 符号なし16ビット整数数値 (unsigned short)
● %x intを符号なし16進数で表示「abcdef」を使用
● %X intを符号なし16進数で表示「ABCDEF」を使用
●%xx 符号あり32ビット整数数値(unsigned long long)。0-9とa-fで表記
●%X 符号あり32ビット整数数値(unsigned long long)。0-9とA-Fで表記
●%f 64ビット浮動小数点数値(double)
●%e 64ビット浮動小数点数値(double)
●%E 64ビット浮動小数点数値(double)
●%g 64ビット浮動小数点数値(double)
●%G 64ビット浮動小数点数値(double)
doubleは8バイト10の-307乗から10の308乗まで 15桁が有効
floatは4バイト 10の-37乗から10の38乗まで 6桁有効
● %e doubleを[-]d.dddd e [+/-]dddの指数表示
● %f doubleを[-]dddd.ddddで表示
● %.2f doubleを小数点第2位まで表示する
● %.1f doubleを小数点第1位まで表示する
● %g doubleをeかfのうち、表現できる精度で短い方で表示
●%c 8ビット文字 \\dddまたは\\udddd フォーマット
●%C 16ビットユニコード文字 \\dddまたは\\udddd フォーマット
●%s NULL終端の8ビット文字列
●%S NULL終端の16ビットユニコード文字
●%p ポインタ
%-33s
%08lx
こんな使い方もできる
- (void)doesNotRecognizeSelector:(SEL)aSelector {
NSLog(@"doesNotRecognizeSelector: %s", aSelector);
}
//NSLog(@"[CLASS dealloc] %p", self);
● \n 改行
● \r
返り値
( void )
なし
引数
( NSString * )format
( ... )...
フレームワーク
Foundation
クラス
NSLog
Function
使用可能
10.0
参照
NSLogv
例文
NSLog([sender alternateTitle]); NSLog(@"theMessage"); NSLog( @"\t aaaaa: %@", [ theObject className ] ); NSLog( @"\t bbbbb: %@",[ theObject description ] ); NSLog( @"%@%@%@%@", @"aaaaa", @"bbbbbbb", [ NSString stringWithCharacters:[ theMutableData mutableBytes ] length:4 ], @"ddddddd" ); NSLog(@"image_type = %c%c%c%c", type[0], type[1], type[2], type[3]); NSLog(@"eype %d", err); NSLog(@"undoForMoveAnchor %zd", theselectPathNumber);
NSUbiquitousKeyValueStoreクラス
INDEX>Foundation>NSUbiquitousKeyValueStore
継承 | NSObject |
準拠 | NSObject (NSObject) |
フレームワーク | /System/Library/Frameworks/Foundation.framework |
使用可能 | OS X 10.7以降 |
iOS 5.0以降 | |
定義 | NSUbiquitousKeyValueStore.h |
解説
iCloudアカウントに接続された全てのデバイス上の設定のためのキーバリューストア
共有インスタンスの取得
共有iCloudのキーバリューストアオブジェクトを取得するには(+ defaultStore)メソッドを使います。
#pragma mark cloud Key-Value Store -(void)method002 { // NSUbiquitousKeyValueStore *aStore = [NSUbiquitousKeyValueStore defaultStore]; [aStore setString:@"oomori" forKey:@"name"]; [aStore setDouble:44.0 forKey:@"age"]; if ([aStore synchronize]) { NSLog(@"%s :sync OK", __FUNCTION__); }else { NSLog(@"NO"); } //=>[OOOAppDelegate method002] :sync OK }
値の取得
キーで配列を取得するには(– arrayForKey)メソッドを使用します。
キーでブール値を取得するには(– boolForKey)メソッドを使用します。
キーでデータオブジェクトを取得するには(– dataForKey)メソッドを使用します。
キーで辞書オブジェクトを取得するには(– dictionaryForKey)メソッドを使用します。
キーでdouble値を取得するには(– doubleForKey)メソッドを使用します。
キーでlong long値を取得するには(– longLongForKey)メソッドを使用します。
キーでオブジェクトを取得するには(– objectForKey)メソッドを使用します。
キーで文字オブジェクトを取得するには(– stringForKey)メソッドを使用します。
値の設定
キーバリューストアで指定されたキーの配列オブジェクトを設定します。
– setArray:forKey
キーバリューストアで指定されたキーのブール値を設定します。
– setBool:forKey
キーバリューストアで指定されたキーのデータオブジェクトを設定します。
– setData:forKey
キーバリューストアで指定されたキーの辞書オブジェクトを設定します。
– setDictionary:forKey
キーバリューストアで指定されたキーのdouble値を設定します。
– setDouble:forKey
キーバリューストアで指定されたキーのlong long値を設定します。
– setLongLong:forKey
キーバリューストアで指定されたキーのオブジェクト値を設定します。
– setObject:forKey
キーバリューストアで指定されたキーの文字列値を設定します。
– setString:forKey
ディスクとメモリのシンクロナイズ
明示的にディスクに格納されているものとメモリ内のキーと値を同期します。
– synchronize
キーの除去
キーバリューストアから指定されたキーに関連づけられた値を削除します。
– removeObjectForKey
現在のキーと値の取り出し
キーバリューストア内のキーと値のデータを格納した辞書を返します。
– dictionaryRepresentation
定数
サブクラス化の注意
NSTextCheckingResultクラス
INDEX>Foundation>NSTextCheckingResult
解説
継承 | NSObject |
準拠 | NSCoding |
NSCopying | |
NSObject (NSObject) | |
フレームワーク | /System/Library/Frameworks/Foundation.framework |
使用可能 | OS X 10.6以降 |
iOS 4.0以降 | |
定義 | NSTextCheckingResult.h |
概要
メソッド
テキストチェックの範囲とタイプ
range property
resultType property
numberOfRanges property
– rangeAtIndex
テキストチェックの置換結果
+ replacementCheckingResultWithRange:replacementString
replacementString property
正規表現でのテキストチェックの結果
+ regularExpressionCheckingResultWithRanges:count:regularExpression
regularExpression property
テキストチェックの結果コンポーネント
components property
URLのテキストチェック
+ linkCheckingResultWithRange:URL
URL property
アドレスのテキストチェックの結果
+ addressCheckingResultWithRange:components
addressComponents property
変換情報のテキストチェック結果
電話番号のテキストチェックの結果
+ phoneNumberCheckingResultWithRange:phoneNumber
phoneNumber property
日付と時間のテキストチェックの結果
+ dateCheckingResultWithRange:date
+ dateCheckingResultWithRange:date:timeZone:duration
date property
duration property
timeZone property
タイポグラフィーのテキストチェックの結果
+ dashCheckingResultWithRange:replacementString
+ quoteCheckingResultWithRange:replacementString
綴りのチェック結果
+ orthographyCheckingResultWithRange:orthography
orthography property
文法のテキストチェックの結果
+ grammarCheckingResultWithRange:details
grammarDetails property
テキストチェック結果の適用範囲
定数
サブクラス化の注意
NSOrthographyクラス
Index>Foundation>NSOrthography
解説
テキストの言語・スクリプトなどを表すクラスです。
継承 | NSObject |
準拠 | NSCoding |
NSCopying | |
NSObject (NSObject) | |
フレームワーク | /System/Library/Frameworks/Foundation.framework |
使用可能 | OS X 10.6以降 |
iOS 4.0以降 | |
定義 | NSOrthography.h |
概要
本クラスについて
テキストの言語・スクリプトなどを表すクラスです。NSLinguisticTaggerクラスなどと組み合わせて文章の構文解析の際に使用します。iOS5.1では、英語のみ品詞の解析ができるようですが、日本語は形態素解析しかできない状態のようです。
NSOrthographyオブジェクトを作成
NSOrthographyオブジェクトを作成するには(+ orthographyWithDominantScript:languageMap)メソッドを使用します。
allocで作成したオブジェクトを初期化するには(– initWithDominantScript:languageMap)メソッドを使用します。
形態素解析を行い、各単語の品詞を調べるサンプル
#pragma mark NSOrthography orthographyWithDominantScript: -(void)method001 { NSString *textToAnalyse = @"That Japanese restaurant has a really authentic atmosphere."; //パースしたときの文字の要素の範囲 NSRange stringRange = NSMakeRange(0, textToAnalyse.length); // 言語マップの辞書 NSArray *language = [NSArray arrayWithObjects:@"en",@"de",@"fr",nil]; NSDictionary* languageMap = [NSDictionary dictionaryWithObject:language forKey:@"Latn"]; NSOrthography *orthography = [NSOrthography orthographyWithDominantScript:@"Latn" languageMap:languageMap]; [textToAnalyse enumerateLinguisticTagsInRange:stringRange scheme:NSLinguisticTagSchemeLexicalClass options:(NSLinguisticTaggerOmitWhitespace | NSLinguisticTaggerOmitPunctuation) orthography:orthography usingBlock:^(NSString *tag, NSRange tokenRange, NSRange sentenceRange, BOOL *stop) { NSLog(@"\"%@\" is a %@, tokenRange (%d,%d), sentenceRange (%d-%d)",[textToAnalyse substringWithRange:tokenRange] ,tag,tokenRange.location,tokenRange.length, sentenceRange.location, sentenceRange.length); }]; //=>"That" is a Determiner, tokenRange (0,4), sentenceRange (0-59) //=>"Japanese" is a Adjective, tokenRange (5,8), sentenceRange (0-59) //=>"restaurant" is a Noun, tokenRange (14,10), sentenceRange (0-59) // ... }
言語とスクリプトの管理
解析の結果、含まれる言語のコードを取得するには(allLanguages)プロパティを参照します。読み取り専用です。enやjaなどのコードです。
解析の結果、含まれるスクリプトを取得するには(allScripts)プロパティを参照します。読み取り専用です。LatnやJpanなどのコードです。
解析の結果、含まれる言語マップを取得するには(languageMap)プロパティを参照します。読み取り専用です。Jpan = (ja);などスクリプトと言語の関連づけがなされた辞書です。
テキストのなかで大勢を占める言語を取得するには(dominantLanguage)プロパティを参照します。読み取り専用です。
テキストの中で大勢を占めるスクリプトを取得するには(dominantScript)プロパティを参照します。読み取り専用です。
指定したスクリプトの言語を返すには(– languagesForScript)メソッドを使用します。指定したスクリプトの大勢を占める言語を返すには(– dominantLanguageForScript)メソッドを使用します。
テキストを与えて解析させるサンプル
#pragma mark NSOrthography property -(void)method002 { NSString *aString = @"This is iOS code. これは日本語です。"; NSRange aRange = NSMakeRange (1, [aString length]-1); NSString *tagScheme = NSLinguisticTagSchemeNameType; NSLinguisticTaggerOptions opts = NSLinguisticTaggerOmitPunctuation; NSArray *supportedLanguage = [NSLinguisticTagger availableTagSchemesForLanguage:@"en"]; NSLinguisticTagger *t = [[NSLinguisticTagger alloc] initWithTagSchemes:supportedLanguage options: NSLinguisticTaggerOmitPunctuation] ; [t setString:aString]; [t enumerateTagsInRange: aRange scheme: tagScheme options:(NSLinguisticTaggerOptions)opts usingBlock:^(NSString *tag, NSRange tokenRange, NSRange sentenceRange, BOOL *stop) { NSLog(@"%@", tag); }]; [t enumerateTagsInRange: aRange scheme: NSLinguisticTagSchemeNameTypeOrLexicalClass options:(NSLinguisticTaggerOptions) opts usingBlock:^(NSString *tag, NSRange tokenRange, NSRange sentenceRange, BOOL *stop) { NSLog(@"%@", tag); }]; NSRange effectiveRange; NSOrthography *orthography = [t orthographyAtIndex:aRange.location effectiveRange:&effectiveRange]; NSLog(@"%u,%u,%@",effectiveRange.location,effectiveRange.length,orthography.allLanguages); NSLog(@"%u,%u,%@",effectiveRange.location,effectiveRange.length,orthography.allScripts); NSLog(@"%u,%u,%@",effectiveRange.location,effectiveRange.length,orthography.dominantLanguage); NSLog(@"%u,%u,%@",effectiveRange.location,effectiveRange.length,orthography.dominantScript); NSLog(@"%u,%u,%@",effectiveRange.location,effectiveRange.length,orthography.languageMap); NSLog(@"%s %@",__FUNCTION__,[orthography languagesForScript:@"Jpan"]); NSLog(@"%s %@",__FUNCTION__,[orthography dominantLanguageForScript:@"Jpan"]); }
メソッド
NSOrthographyのインスタンスの作成
+ orthographyWithDominantScript:languageMap
– initWithDominantScript:languageMap
言語マップの定義
dominantScript property
languageMap property
言語とスクリプトの管理
– languagesForScript
– dominantLanguageForScript
allLanguages property
allScripts property
dominantLanguage property
定数