Merged
Conversation
added 4 commits
November 26, 2023 15:19
Swift 側で print した時の結果を Unity 側で取得できるようにする。
## NSObject と AnyObject を分けている理由
NSObject と Swift クラスの出力形式は異なっている。
NSObject
```
<CBMutableCharacteristic: 0x2c54b6f00 UUID = EA521290-A651-4FA0-A958-0CE73F4DAE55, Value = (null), Properties = 0x1, Permissions = 0x1, Descriptors = (null), SubscribedCentrals = ()>
```
<クラス名: アドレス 中身>
のフォーマット
このアドレスはアンマネージドなオブジェクトのメモリアドレスだが、Unity側から見るとマネージドなオブジェクトのアドレスのように見えてしまう。
そこで、NSObject では正規表現を用いてアドレス部分を削除している。
## 中身がない場合
クラス名返す。Swift の挙動と同じ
## クラスがネストする場合。
```
service: CBMutableService: Primary = YES, UUID = 068C47B7-FC04-4D47-975A-7952BE1A576F, Included Services = (null), Characteristics = (
"<CBMutableCharacteristic: 0x2a199b5f0 UUID = E3737B3F-A08D-405B-B32D-35A8F6C64C5D, Value = (null), Properties = 0x16, Permissions = 0x3, Descriptors = (null), SubscribedCentrals = (\n)>"
```
アドレスは表示されてします。
ここの対応は手間なため許容
変えたければ上書きすれば良い。
any_object_get_descriptionのほうがより適切かもしれないため迷っているが、csharp 寄りの命名にする ## print で出す文言 https://developer.apple.com/documentation/swift/string/init(describing:)-67ncf ## ラップしたクラスの出力 CustomStringConvertible を用いて上書き https://developer.apple.com/documentation/swift/customstringconvertible description 直呼びは非推奨とあるが、Stringのコンストラクタを使う場合 Optional から取り出す必要があるため楽さを優先
CBPeripheralManager, CBCentralManager等のクラス名しか表示されなかったものに関しては ToString を定義していない
added 2 commits
November 26, 2023 15:30
properties や permissions が数値になってむしろ読みづらくなっているが、必要であれば自分で中身をLogにだせば良いだけのため、 ここで綺麗にする必要はあまりないと判断。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Swift 側で print した時の結果を Unity 側で取得できるようにする。
NSObject と AnyObject を分けている理由
NSObject と Swift クラスの出力形式は異なっている。
NSObject
<クラス名: アドレス 中身>
のフォーマット
このアドレスはアンマネージドなオブジェクトのメモリアドレスだが、Unity側から見るとマネージドなオブジェクトのアドレスのように見えてしまう。
そこで、NSObject では正規表現を用いてアドレス部分を削除している。
中身がない場合
クラス名返す。Swift の挙動と同じ
クラスがネストする場合。
アドレスは表示されてします。
ここの対応は手間なため許容
変えたければ上書きすれば良い。
Test
SampleDebug シーンを使ってどんな値が出力されるか確認した。