大步了解

时间:2016-11-23 19:56:45

标签: swift

我从某个地方获得了这段代码:

    for y in (0 as CGFloat).stride(from: 0.0, to: rect.height, by: elementSize)

问题:

  1. 那是什么? stride应该看起来像for i in stride(from: 1, to: 10, by: 3)
  2. Swift 3 y CGFloatInts时,它会给出错误当然是如何让它发挥作用?当在正确的表单中使用这些参数时,我会收到有关仅仅采用template<class T>struct tag_t{using type=T; constexpr tag_t(){};}; template<class T>constexpr tag_t<T> tag{}; template<class Tag>using type_t=typename Tag::type; #define TAG2TYPE(...) type_t<decltype(__VA_ARGS__)> // takes args... // returns a function object that takes a function object f // and invokes f, each time passing it one of the args... template<class...Args> auto expand( Args&&...args ) { return [&](auto&& f)->decltype(auto) { using discard=int[]; (void)discard{0,(void( f( std::forward<Args>(args) ) ),0)...}; }; } template <typename TF> void post(TF){ } template <typename... TFs> struct funcs : TFs... { funcs(TFs... fs) : TFs{fs}... { } void call() { expand( tag<TFs>... ) ([&](auto tag){ post(static_cast< TAG2TYPE(tag)& >(*this)()); }); } }; 的步幅的错误?

1 个答案:

答案 0 :(得分:3)

1)。那不是Swift 3

2)。

for y : CGFloat in stride(from: 0.0, to: 10.0, by: 0.5)
{
    print(y)
}

PS:循环上升到9.5。如果您需要达到10.0,则需要

for y : CGFloat in stride(from: 0.0, through: 10.0, by: 0.5) { ...