前提・実現したいこと
Objective-CもSwiftも初心者なので漠然とした質問になってしまいますが、、、
先日SwiftからObjective-Cの関数を呼び出すようにしており、その時には気がつかなかったのですが、SwiftでexportItem(toId: songId.description)と関数を実行してて、それなのにexportItemToId:(NSString *)songidが呼び出されておりました。
やりたいことは、exportItemToId:(NSString *)songidで間違い無いので問題は無いのですが、入力保管でもexportItemが出てきてしまい、理解できません。
ヘッダーファイルも作成しており、そこでもexportItemToIdと宣言しています。
なので、どのような仕組みで関数名が違うのに実行できているのか教えて頂きたいです...
該当のソースコード
ViewController.swift
全文だと長いので、関係ない部分を削除しております。
Objective
1//import Foundation 2import UIKit 3import MediaPlayer 4import AVFoundation 5 6class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { 7 8 let instanceOfObjcMethod: ObjcMethod = ObjcMethod() 9 10 // 選択した音楽を再生 11 func tableView( _ tableView: UITableView, didSelectRowAt indexPath:IndexPath ) { 12 13 // soundIdからMediaItemを取得 14 let songId: NSNumber = albums[indexPath.row].songId 15 print("expotItemを呼び出します") 16 instanceOfObjcMethod.exportItem(toId: songId.description) 17 print("expotItemを呼び出し終わりました") 18 } 19} 20
ObjcSwift.h
Objective
1#import <Foundation/Foundation.h> 2 3#ifndef ObjcSwift_h 4#define ObjcSwift_h 5 6@interface ObjcMethod : NSObject 7 8- (BOOL) exportItemToId: (NSString*) songId; 9- (void) setDoDisplay: () _ ; 10 11@end 12 13#endif /* ObjcSwift_h */
Unity-iPhone-Bridging-Header.h
Objective
1#import <Foundation/Foundation.h> 2#import <UIKit/UIKit.h> 3#import "UnityInterface.h" 4 5#import "ObjcSwift.h"
MusicLibraryMediaPicker.mm
全文だと長いので、関係ない部分を削除しております。
Objective
1 2# import "ObjcSwift.h" 3 4extern "C" { 5 BOOL exportItem (MPMediaItem *item); 6 7 /******************************** 8 * クラスを作って処理している 9 ********************************/ 10 @implementation ObjcMethod: NSObject 11 12 /************************************** 13 * 曲IDをもとにエクスポートする関数 14 * @param songId エクスポートしたい曲ID 15 * @return エクスポートが完了したらYESを返す 16 **************************************/ 17 - (BOOL) exportItemToId: (NSString*) songId { 18 NSLog(@"!!!!!!!!exportItemToId呼ばれたよ!!!!!!!"); 19 // char*型の文字列を変換 20 NSString* s_id = [NSString stringWithFormat:@"%@",songId]; 21 MPMediaQuery* songQuery = [MPMediaQuery songsQuery]; 22 [songQuery addFilterPredicate:[MPMediaPropertyPredicate predicateWithValue:[NSNumber numberWithBool:NO] forProperty:MPMediaItemPropertyIsCloudItem]]; 23 NSArray *songlists = songQuery.collections; 24 for (MPMediaItemCollection *songlist in songlists) { 25 MPMediaItem *representativeItem = [songlist representativeItem]; 26 NSString* PersistentID = [NSString stringWithFormat:@"%@", [representativeItem valueForProperty:MPMediaItemPropertyPersistentID]]; 27 if ( ![representativeItem hasProtectedAsset] && [s_id isEqualToString:PersistentID] ) { 28 sid = [[representativeItem valueForProperty:MPMediaItemPropertyPersistentID] longValue]; 29 sname = [representativeItem valueForProperty:MPMediaItemPropertyTitle]; 30 albumArtwork = [representativeItem.artwork imageWithSize:representativeItem.artwork.bounds.size]; 31 NSLog(@"見つかりました!"); 32 NSLog(@"セットします!![sid:%ld, sname:%@]:", sid, sname); 33 return YES; 34 } 35 } 36 return NO; 37 } 38 @end 39}
実行結果
expotItemを呼び出します 2020-03-09 07:06:42.756224+0900 SoundStory[343:9123] !!!!!!!!exportItemToId呼ばれたよ!!!!!!! 2020-03-09 07:06:42.772364+0900 SoundStory[343:9123] 見つかりました! 2020-03-09 07:06:42.772549+0900 SoundStory[343:9123] セットします!![sid:6821698684411020667, sname:ココロ自由宣言]: expotItemを呼び出し終わりました
初歩的な質問で恐縮ですがよろしくお願い致します????♂️????♂️
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/03/09 06:15
2020/03/09 06:23
2020/03/09 10:08
2020/03/09 10:22
2020/03/09 10:38
2020/03/09 10:46
2020/03/09 11:57