ios - creation of realm file in App-Group Folder does not work under WatchOS (WatchKit Extension) -
the following code works under ios-8.x / swift-1.2 / watchkit-1.0
// create realm_db-file in shared app-groups folder let directory: nsurl = nsfilemanager.defaultmanager().containerurlforsecurityapplicationgroupidentifier(appconstants.app_group_identifier_key)! let realmpath = directory.path!.stringbyappendingpathcomponent(appconstants.realm_filename_key) playerrealm = realm.init(path: realmpath)
but doesn't work under ios-9.0.1 / swift-2.0 / watchos-2.0
the 2 error messages are:
1.) 'stringbyappendingpatchcomponent' unavailable: use urlbyappendingpathcomponent on nsurl instead
2.) call can throw, not marked 'try' , error not handled
any appreciated !
to fix first issue, need cast:
directory.path nsstring
since path returning string
, in swift doesn't offer stringbyappendingpathcomponent
method.
second, swift 2.0 has new error handling, methods can throw error labeled throws
. these methods require add try
before call. see apple's docs on this: swift error handling
to disable error handling if know path guaranteed work can simple write:
playerrealm = try! realm(path: realmpath)
Comments
Post a Comment