in swift if have global constant such let host = xxx in file, change of constant cause project files recompiled
correct, changing @ scope cause recompile.
just same if change constant in specific class, class recompiled.
if need change values outside of code, e.g. host
it's better use plist file properties in it.
example:
settings.plist:
<?xml version="1.0" encoding="utf-8"?> <!doctype plist public "-//apple//dtd plist 1.0//en" "http://www.apple.com/dtds/propertylist-1.0.dtd"> <plist version="1.0"> <dict> <key>host</key> <string>1.2.3.4</string> </dict> </plist>
example code value:
guard let settingsfileurl = nsbundle.mainbundle().urlforresource("settings", withextension: "plst") else { fatalerror("unable find plist file") } let settings = nsdictionary(contentsofurl: settingsfileurl) guard let host = settings?.valueforkey("host") as? string else { fatalerror("unable host value plist file") } print("host = \(host)")
Comments
Post a Comment