DX・デジタルトランスフォーメーション

AppStoreにて無料公開中! ”システム手帳”で検索! - AppStoreへ iPad版 - iPhone版

ブロックチェーン・暗号技術 | android | iOS | Web | アプリの著作権 | 日本のなりたち | 禅・大乗仏教 | 新しい社会

iOS(Objective-C)とandroid(Java)のディレクティブ対応表

iOS(Objective-C)とandroid(Java)の対応表

iPhoneアプリをandroidアプリに移行する際やandroidアプリをiOSアプリに移行する際などに頻繁に使用するディレクティブをまとめた。

ObjectiveCもJavaもLanguageCから派生した言語のため、frameworkに依存しないディレクティブはほぼ同じ。

cocoa frameworkとandroid sdkについてもcocoaはプレフィックスが付くがandroidはプレフィックスが付かない程度の違いでほぼ同じといえる。

ObjectiveC

Java

文字列


NSString *


String

ミュータブル配列


NSMutableArray *	


List<>

連想配列


NSMutableDictionary *	


Map<>

セマフォ生成


dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);


Semaphore semaphore = new Semaphore(0);

セマフォ通知受信


dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);


try {
  semaphore.acquire();
} catch (
  InterruptedException ex) {
}

セマフォ通知


dispatch_semaphore_signal(semaphore);


semaphore.release();

特定文字で分割


NSArray *separated = [path componentsSeparatedByString:@"#"];


String[] separated = path.split(Pattern.quote("#"), 0);

特定文字置き換え


NSString *url = [aString stringByReplacingOccurrencesOfString:@"https://" withString:@""];


String url = aString.replaceAll("https://", "");

文字列の連結


NSString *entrys = [entrys stringByAppendingString:[NSString stringWithFormat:@"<img src=%@ />", url]];


StringBuilder entrys = entrys.append(String.format("<img src=%s />", url));

メソッドで変更した内容を引数で受け取る方法


NSString *mutableString;
[self method:&mutableString];


StringBuilder mutableString = new StringBuilder(aString);
method(mutableString);

文字列をtrancateする


NSString *subString = [aString substringWithRange:stringRange];


String subString = aString.substring(0, 8);

printf構文で文字列を整形


NSString *url = [NSString stringWithFormat:@"https://aaa.com/%@/", text];


String url = String.format("https://aaa.com/%s/", text);

コレクション(配列、連想配列)操作


for (NSString * in NSArray) {
}


for(String s : Map) {
}

アラート表示


UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:NSLocalizedString(@"AlertMessage", @"") preferredStyle:UIAlertControllerStyleAlert];

[alertController addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"OK", @"") style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
}]];

[self presentViewController:alertController animated:YES completion:^{
}];


new AlertDialog.Builder(this)
        .setTitle("")
        .setMessage(alertMessage)
        .setPositiveButton(R.string.Ok, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
            }
        })
        .show();

メインスレッド(UIスレッド)で画面変更


dispatch_async(dispatch_get_main_queue(), ^{
});


Activity#runOnUiThread(new Runnable() {
  @Override
  public void run() {
  }
});

サブスレッドで実行


dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
});


(new Thread(new Runnable() {
    @Override
    public void run() {
    }
})).start();

ローディングインジケータ表示 Loading Indicator


UIActivityIndicatorView *mIndicator;
[mIndicator startAnimating];


findViewById(R.id.loadingIndicator).setVisibility(VISIBLE);

<ProgressBar
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:id="@+id/loadingIndicator"
    android:indeterminateOnly="true"
    android:keepScreenOn="true"
    android:layout_gravity="right|center_vertical"
    android:layout_marginRight="8dp"
    android:visibility="invisible" />

2023年12月
     12
3456789
10111213141516
17181920212223
24252627282930
31      
android
iOS
web
アプリの著作権
ブロックチェーン/暗号技術
新しい社会
禅・大乗仏教
日本のなりたち

AppStoreにて無料公開中! ”システム手帳”で検索! - AppStoreへ iPad版 - iPhone版
デジタルトランスフォーメーションで新しい生活を提案!