dankogai/swift-complex

import CoreGraphics

palmerc opened this issue · 5 comments

complex.swift uses CGFloat and you might want to import CoreGraphics not just Foundation.

Foundation suffices for the use by Complex. I would like to keep import as minimalistic as possible.

Doesn't work for me without it. I get an error on CGFloat. Are you importing it somewhere else?

No. just Foundation.

Remember that you have to import whatever you need even if complex.swift imports it. For instance the following code does not work without import Foundation or import Darwin The following REPL session illustrate that. In this case atan2 is missing.

% make repl
xcrun -sdk macosx swiftc -emit-library -emit-module complex/complex.swift complex/exops.swift -module-name Complex
swift -I. -L. -lComplex
Welcome to Apple Swift version 2.1.1 (swiftlang-700.1.101.15 clang-700.1.81). Type :help for assistance.
  1> import Complex
  2> Complex(abs: 2.0, arg:atan2(1,1))
repl.swift:2:23: error: use of unresolved identifier 'atan2'
Complex(abs: 2.0, arg:atan2(1,1))
                      ^~~~~

  2> import Foundation
  3> Complex(abs: 2.0, arg:atan2(1,1)) 
$R0: Complex.Complex<Double> = {
  re = 1.4142135623730951
  im = 1.4142135623730949
}
  4>  

OK, but you’re referencing CGFloat which is a struct defined in CoreGraphics not in Foundation.

init(_: CGFloat)

cameron.

On 22. jan. 2016, at 17.39, Dan Kogai notifications@github.com wrote:

No. just Foundation.

Remember that you have to import whatever you need even if complex.swift imports it. For instance the following code does not work without import Foundation or import Darwin The following REPL session illustrate that. In this case atan2 is missing.

% make repl
xcrun -sdk macosx swiftc -emit-library -emit-module complex/complex.swift complex/exops.swift -module-name Complex
swift -I. -L. -lComplex
Welcome to Apple Swift version 2.1.1 (swiftlang-700.1.101.15 clang-700.1.81). Type :help for assistance.
1> import Complex
2> Complex(abs: 2.0, arg:atan2(1,1))
repl.swift:2:23: error: use of unresolved identifier 'atan2'
Complex(abs: 2.0, arg:atan2(1,1))
^~~~~

2> import Foundation
3> Complex(abs: 2.0, arg:atan2(1,1))
$R0: Complex.Complex = {
re = 1.4142135623730951
im = 1.4142135623730949
}
4>

Reply to this email directly or view it on GitHub #11 (comment).

I replaced import Foundation with import Darwin and import CoreGraphics

f1a3145

So you are right -- about iOS (and maybe tvOS)