arrays - Swift count string size in for loop -


for homework assignment have convert sentence user has typed in 3 different ways.

  • convert letters uppercase(completed)
  • convert letters lowercase(completed)
  • convert uppercase letters lowercase , vice versa(having trouble)

i believe logic correct don't know wrong.

this code:

// //  viewcontroller.swift //  lower upper converter // //  created mac user on 9/27/15. //  copyright © 2015 omid nassir. rights reserved. //  import uikit  class viewcontroller: uiviewcontroller {     private var input = ""     private var = 0     var sentense = [string]()     //var sentensechar: [character] = []     //input fields     @iboutlet weak var input1: uitextfield!      @iboutlet weak var input2: uitextfield!         //caps button     @ibaction func capsbtn(sender: anyobject)     {         if input1.text != nil         {             input = input1.text!.uppercasestring             input2.text = input         }         else         {             input2.text = ""         }     }      //lower case button     @ibaction func lowsbtn(sender: anyobject)     {         if input1.text != nil         {             input = input1.text!.lowercasestring             input2.text = input         }         else         {             input2.text = ""         }     }       //word converter button     @ibaction func capslowsbtn(sender: anyobject)     {          if input1.text != nil         {            i=0; < count(input1.text); i++           {             input = advance(input1.startindex, i)             str[input]             sentense[i] = advance(input.startindex, i)           }            }      }//end of convert function       override func viewdidload() {         super.viewdidload()         // additional setup after loading view, typically nib.     }      override func didreceivememorywarning() {         super.didreceivememorywarning()         // dispose of resources can recreated.     }   } 

i getting error message:

 cannot invoke 'count' argument list of type '(string?)' 

for statement: for i=0; < count(input1.text); i++

note! swift 2 have use new syntax:

change code to:

for var = 0; < input1.text!.characters.count; i++ {     ... } 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -