Wrox Programmer Forums
|
BOOK: Beginning Swift Programming
This is the forum to discuss the Wrox book Beginning Swift Programming by Wei-Meng Lee; ISBN: 978-1-119-00931-3
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Swift Programming section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 4th, 2015, 12:56 AM
Registered User
 
Join Date: Mar 2015
Posts: 1
Thanks: 0
Thanked 1 Time in 1 Post
Default CH 3 Interoperabilty with NSString

I could not get this code to work. Xcode reports containsString unknown selector.

Code:
var str1 = "This is a Swift string"
println((str1 as NSString).containsString("Swift")) ---true---
You need to be running OS 10.10 before this will work. I'm on 10.9.

Mitch
The Following User Says Thank You to Mitchb For This Useful Post:
 
Old June 24th, 2015, 07:04 AM
Registered User
 
Join Date: Jun 2015
Posts: 1
Thanks: 0
Thanked 1 Time in 1 Post
Default

In chap 3, another error codes for character type conversion to NSString.

var bouquet = "\u{1F490}" // Character

println((bouquet as NSString).length) //Err: Character can't be converted to NSString

println(bouquet)
println("\(bouquet)") // String
println(String(bouquet)) // Character to String
println(count("\(bouquet)")) //---1---
println(count(String(bouquet))) //---1---

From above, you have to convert a Chacater to be a String by String() typecast, then to NSString. It will get error by "as NSString" directly.

println((NSString(string:String(bouquet)))) // Convert a character to a NSString
println((NSString(string:String(bouquet))).length) // ---2---


Leon
The Following User Says Thank You to leonwang777 For This Useful Post:





Similar Threads
Thread Thread Starter Forum Replies Last Post
Ch 4 and Ch 13/15 - controls and the DataPager AlanWheeler BOOK: Beginning ASP.NET 4.5 : in C# and VB 3 February 24th, 2014 04:56 PM
Sending NSString to another viewController nickpsaris BOOK: Professional iPhone and iPad Database Application Programming 1 January 19th, 2012 12:54 AM
Ch 9-but will learn more abt User Controls (ch 8) btcomp BOOK: Beginning ASP.NET 4 : in C# and VB 1 August 24th, 2010 11:40 AM
Search ch 13, ch 16 sporik BOOK: Beginning PHP 6, Apache, MySQL 6 Web Development ISBN: 9780470391143 0 October 27th, 2009 04:44 PM
Ch. 4 & Ch. 12 athena BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 0 July 23rd, 2004 10:54 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.