replacementOccurrences的字符串错误

时间:2017-04-17 04:30:15

标签: swift

对于以下Swift 3代码:

var password = "Mary had a little lamp"
var newPassword = password.replacingOccurrences(of: "a", with: "A")

我在调用replacingOccurrences时遇到此错误:

  

类型'String'的值没有成员'replacementOccurrences'

2 个答案:

答案 0 :(得分:1)

试试这个,在swift3中工作

#include<stdio.h>
#define N 4

bool mazeUtil(int[N][N] maze,int x, int y, sol[N][N]);-->Compile time error at this line number.

    int main() {
      return 0;
    }
bool mazeUtil(int[][] maze,int x, int y,int[][] sol){
     if(isSafe){
          sol[x][y] = 1;
         if(mazeUtil(maze,x+1,y,sol)==true){
            return true;
          }
         if(mazeUtil(maze,x,y,sol)==true){
            return true;
           }
          sol[x][y]=0;
      }
      return false;
   }

答案 1 :(得分:0)

var newPassword = password.replacingOccurrences(of: "a", with: "A", options: NSString.CompareOptions.literal, range: nil)

那些遇到未解析标识符“NSString”问题的人,记得导入 Foundation。