iphone - Swift Remove a given value from an array -


मेरे पास एक सरल सरणी है

  var चश्मा: [स्ट्रिंग] = [बटन 1, बटन (बटन 2, बटन 3, बटन 4)  

कैसे मैं अपने गुम में एक निश्चित मान (प्रकार बटन 3) पा सकता है और इसलिए रद्द कर सकता हूँ?

आप अनुक्रमणिका को पुनः प्राप्त करने के लिए find () वैश्विक फ़ंक्शन का उपयोग कर सकते हैं:

  var ऐनक: [स्ट्रिंग ] = ["बटन 1", "बटन 2", "बटन 3", "बटन 4"] सूचकांक = खोजने दें (चश्मा, "बटन 3")  

और फिर, एक बार सत्यापित हुआ कि तत्व मौजूद है ( ढूंढें एक विकल्प देता है), इसे हटा दें:

  यदि अनुक्रमणिका = अनुक्रमणिका {specs.removeAtIndex (index)}  

Comments

Popular posts from this blog

HTML/CSS - Automatically set height width from background image? -

php - Mysql Show Process - Sleep Commands and what to do -

c - What is the address of buf (the local variable in the main function)? -