Swift 4如何获取字符串的前30个[复制]

Swift 4 How can I get the first 30 of a string [duplicate]

This question already has an answer here:

I have just updated to Swift 4 and I am finding it difficult to show the first 30 characters of a string. I have a TableView that gets data via Json and that is populating a label. Now since Substrings can not be used anymore I am having a hard time getting this to work. I am essentially checking if the string returned has 30 or more characters and if it does then I want to show only those 30 characters else show everything since it's under 30 characters .... This is my code

 if streamsModel.Posts[indexPath.row].count >= 30
       {
        // Show 30 characters here
        cell.post.text = streamsModel.Posts[indexPath.row]   
       //.substringFromIndex(cell.post.text.endIndex.advancedBy(-4))

        }
        else
       {
        cell.post.text = streamsModel.Posts[indexPath.row]
        }
        cell.post.tag = indexPath.row