6

Xcode Swift - Spacing for Apple build cards

 2 years ago
source link: https://www.codesd.com/item/xcode-swift-spacing-for-apple-build-cards.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Xcode Swift - Spacing for Apple build cards

advertisements

I'm new to Xcode and swift.

When the user types in their address in the textFields and then goes to press the 'ViewOnMap' Button,(Redirect the user to Apple's built-in maps) it makes their address search into one line without any spacing. This result obviously returns with 'No location Found'.

I'm pretty sure its because there are no spacing?

I've tried looking at other StackOverflows solved questions on how to add spacing which i've done below:

code:

    @IBAction func btnViewOnMap(sender: AnyObject) {

    var urlString: String?

    let stringURLSearch = "http://maps.apple.com/?q=\(urlString)" + self.textFieldAddress1!.text! + self.textFieldAddress2!.text! + self.textFieldAddress3!.text! + self.textFieldTownCity!.text! + self.textFieldCounty!.text! + self.textFieldPostcode!.text!
    urlString = stringURLSearch.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet())!
    UIApplication.sharedApplication().openURL(NSURL(string: stringURLSearch)!)
}

As you can see the 'urlString' is what others have been saying to put, so that it adds the '%20' but it keeps returning nil.

Thanks in advance!


Have You try to use encoded urlString instead of stringURLSearch with NSURL like this

let stringURLSearch = "http://maps.apple.com/?q=" + self.textFieldAddress1!.text! + self.textFieldAddress2!.text! + self.textFieldAddress3!.text! + self.textFieldTownCity!.text! + self.textFieldCounty!.text! + self.textFieldPostcode!.text!
urlString = stringURLSearch.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet())!
UIApplication.sharedApplication().openURL(NSURL(string: urlString)!)


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK