質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Objective-C

Objective-Cはオブジェクト指向型のプログラミング言語のひとつです。C言語をベースにSmalltalkが取り入れられています。

Xcode

Xcodeはソフトウェア開発のための、Appleの統合開発環境です。Mac OSXに付随するかたちで配布されています。

Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

Q&A

1回答

1925閲覧

Objective-Cからswiftの書き換え方が分からない

退会済みユーザー

退会済みユーザー

総合スコア0

Objective-C

Objective-Cはオブジェクト指向型のプログラミング言語のひとつです。C言語をベースにSmalltalkが取り入れられています。

Xcode

Xcodeはソフトウェア開発のための、Appleの統合開発環境です。Mac OSXに付随するかたちで配布されています。

Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

0グッド

0クリップ

投稿2017/09/15 08:05

編集2017/09/15 08:08

すみません、文章が多くてすみませんが、Objective-Cからswiftに変えていただけないでしょうか。
もし無理なら、Objective-Cからswiftに書き換えの方法を教えてください。

import "ViewController.h" import "BSRCentralManager.h" import "BSRPeripheralManager.h" import "BSRUserDefaults.h" import "SVProgressHUD.h" @interface ViewController () <BSREncounterDelegate> @property (nonatomic, strong) NSArray *items; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // ペリフェラル側は初期化しておく // (セントラルはユーザー名の入力が完了してから初期化→スキャン開始する) [[BSRPeripheralManager sharedManager] setDeleagte:self]; UIRefreshControl *refreshCtl = [[UIRefreshControl alloc] init]; [refreshCtl addTarget:self action:@selector(onRefresh:) forControlEvents:UIControlEventValueChanged]; [self.tableView addSubview:refreshCtl]; self.items = [BSRUserDefaults encounters]; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; } - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; // ユーザー名が未決定であればユーザー名入力画面を表示する if (![[BSRUserDefaults username] length]) { [self performSegueWithIdentifier:@"ShowSetting" sender:self]; } // ユーザー名の入力完了 else { // セントラル側は初期化&スキャン開始する [[BSRCentralManager sharedManager] setDeleagte:self]; // ペリフェラル側はキャラクタリスティックを更新する [[BSRPeripheralManager sharedManager] updateUsername]; NSLog(@"Start with username: %@", [BSRUserDefaults username]); } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } // ============================================================================= pragma mark - Private - (void)alertWithUsername:(NSString *)username { NSString *msg = [NSString stringWithFormat:@"%@とすれ違いました!", username]; // バックグラウンド時はローカル通知 if ([[UIApplication sharedApplication] applicationState] != UIApplicationStateActive) { UILocalNotification *notification = [[UILocalNotification alloc] init]; notification.alertBody = msg; notification.fireDate = [NSDate date]; notification.soundName = UILocalNotificationDefaultSoundName; [[UIApplication sharedApplication] scheduleLocalNotification:notification]; } // フォアグラウンドではHUD else { [SVProgressHUD showSuccessWithStatus:msg]; } } // ============================================================================= pragma mark - TableViewDataSource - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [self.items count]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; NSDictionary *encounterDic = self.items[indexPath.row]; cell.textLabel.text = encounterDic[kEncouterDictionaryKeyUsername]; cell.detailTextLabel.text = [(NSDate *)encounterDic[kEncouterDictionaryKeyDate] descriptionWithLocale:[NSLocale currentLocale]]; return cell; } // ============================================================================= #pragma mark - UITableViewDelegate - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:YES]; } // ============================================================================= #pragma mark - BSREncounterDelegate - (void)didEncounterUserWithName:(NSString *)username { LOG_CURRENT_METHOD; dispatch_async(dispatch_get_main_queue(), ^{ // アラート表示 [self alertWithUsername:username]; // すれちがいリストに追加 [BSRUserDefaults addEncounterWithName:username date:[NSDate date]]; self.items = [BSRUserDefaults encounters]; [self.tableView reloadData]; }); } // ============================================================================= #pragma mark - Event Handler - (void)onRefresh:(UIRefreshControl *)sender { [sender beginRefreshing]; self.items = [BSRUserDefaults encounters]; [self.tableView reloadData]; [sender endRefreshing]; } @end

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

fuzzball

2017/09/15 08:24

SwiftとObjective-Cのどちらが分からないのでしょうか?(どちらも分からないというのは無しで)
guest

回答1

0

  1. まずSwiftという言語の基本的な書き方を覚える
  2. Objective-CとSwiftは混在可能なので、少しずつSwiftに書き換える
  3. すべて書き換えたら、Swift特有の書き方に修正する

投稿2017/09/15 08:20

MasakiHori

総合スコア3384

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問