Sharing data between an iOS 8 share extension and main app

You should use NSUserDefaults like this: Save data: objc NSUserDefaults *shared = [[NSUserDefaults alloc] initWithSuiteName:@”group.yougroup”]; [shared setObject:object forKey:@”yourkey”]; [shared synchronize]; swift let defaults = UserDefaults(suiteName: “group.yourgroup”) defaults?.set(5.9, forKey: “yourKey”) Read data: objc NSUserDefaults *shared = [[NSUserDefaults alloc] initWithSuiteName:@”group.yougroup”]; id value = [shared valueForKey:@”yourkey”]; NSLog(@”%@”,value); swift let defaults = UserDefaults(suiteName: “group.yourgroup”) let x = defaults?.double(forKey: “yourKey”) … Read more

How can I use UserDefaults in Swift?

ref: NSUserdefault objectTypes Swift 3 and above Store UserDefaults.standard.set(true, forKey: “Key”) //Bool UserDefaults.standard.set(1, forKey: “Key”) //Integer UserDefaults.standard.set(“TEST”, forKey: “Key”) //setObject Retrieve UserDefaults.standard.bool(forKey: “Key”) UserDefaults.standard.integer(forKey: “Key”) UserDefaults.standard.string(forKey: “Key”) Remove UserDefaults.standard.removeObject(forKey: “Key”) Remove all Keys if let appDomain = Bundle.main.bundleIdentifier { UserDefaults.standard.removePersistentDomain(forName: appDomain) } Swift 2 and below Store NSUserDefaults.standardUserDefaults().setObject(newValue, forKey: “yourkey”) NSUserDefaults.standardUserDefaults().synchronize() Retrieve var returnValue: [NSString]? … Read more

tech