固有的协议一致性

时间:2017-09-12 11:14:05

标签: swift inheritance protocols

我想实现下一个代码结构:

FileInfo info = new FileInfo();

var lines = File.ReadAllLines(row.Cells["colfilelocation"].Value.ToString());
                var fsdLine = lines.FirstOrDefault(line => 
line.Contains(FSD__Line_Identifier));
                info.FSD = fsdLine.Substring(fsdLine.IndexOf(FSD_Identifier) + FSD_Identifier.Length, 7);
                var dataWithAvgVolts = lines.SkipWhile(line => !line.Contains(Data_Start_Point_Identifier)).ToList();

 int index =1;            
 while(index < dataWithAvgVolts.Count())
 {  
  var data = dataWithAvgVolts[index].Split(splitter);
  if(data.Count() >1)
   {
    if(!Convert.ToDouble(data[data.Count()-1]) == 0)
    {
     //set start info 
     break;
   }
  }
 index++;
}
  1. 协议// Base hierarchy definition protocol A {} protocol C { var a: A { get set } } // Specific definition protocol B: A {} struct TestClass: C { var a: B } 需要C类型的变量。
  2. 协议A继承自B
  3. A通过定义TestClass类型的变量来实现C协议(按B的顺序应该是什么)
  4. 但Swift编译器抱怨2不符合协议C,因为TestClass

    为什么Swift编译器将类型Candidate has non-matching type 'B'视为与B类型不匹配?

0 个答案:

没有答案