Instantiating Realm database for Swift 2.0 - best practice?

后端 未结 2 1671
面向向阳花
面向向阳花 2021-01-04 09:38

I\'m wondering what the best practice for instantiating a Realm database is for Swift 2. One of the major differences between Realm for Swift 1.2 and Swift 2 is that the Rea

2条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-04 10:02

    Unless you're actually going to handle the errors you receive, I highly recommend using try!.

    Your second code snippet doesn't work because, if initializing the Realm fails, that realm variable is never assigned to, which is invalid. You could probably work around that by making the realm variable be of type Realm?.

提交回复
热议问题