Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NSUserDefaults does not have a member named 'subscript' #1

Closed
sebastiaanluca opened this issue Jul 14, 2015 · 2 comments
Closed

NSUserDefaults does not have a member named 'subscript' #1

sebastiaanluca opened this issue Jul 14, 2015 · 2 comments

Comments

@sebastiaanluca
Copy link

Don't know if I'm doing something wrong here, but just tried the example and it throws an error.

let userDefaults = NSUserDefaults.standardUserDefaults()

if let myValue = userDefaults["mykey"] as? Bool {..}

NSUserDefaults does not have a member named 'subscript'

If I use objectForKey, it works.

let userDefaults = NSUserDefaults.standardUserDefaults()

if let myValue = userDefaults.objectForKey("mykey") as? Bool {..}

Same situation when trying to modify it. userDefaults["mykey"] = "myvalue" does not work.

@phimage
Copy link
Owner

phimage commented Jul 14, 2015

objectForKey is standard method of NSUserDefaults class, work without using Prephirences framework
Did you use cocoapod? and import the framework in your file?

import Prephirences

For information subscript for NSUserDefaults is defined in NSUserDefaults+Prephirences.swift

@sebastiaanluca
Copy link
Author

The import was the solution! Thought it was a Swift extension of NSUserDefaults, so I could use it without importing anything. Now I can successfully use return self.userDefaults[key] and return self.userDefaults[key]?[preference]. Thanks!

PS: maybe add it to the readme? For us noobs ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants