Skip to content

[SR-138] Foundation objects are not bridged on Linux as they are on OS X. #4378

@swift-ci

Description

@swift-ci
Previous ID SR-138
Radar None
Original Reporter babt (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

OS X 10.11.1, Ubuntu 15.10

Additional Detail from JIRA
Votes 6
Component/s Compiler, Foundation
Labels Bug
Assignee @millenomi
Priority Medium

md5: fd4610a64cf6030b8952ae7fa9bfb6ba

is duplicated by:

  • SR-309 Unable to coerce String -> NSString
  • SR-5160 NSMutableCharacterSet cannot be coerced to CharacterSet under Linux
  • SR-5404 Linux: Cannot cast NSData to Data

Issue Description:

Foundation in this build does include NSString but there's lots a caveats associated with it. It's not bridged to String as it is on OS X yet and I suspect (but haven't verified yet,) that most other Foundation objects that are bridged on OS X are not yet bridged on Linux. So casting as in the example below will fail:

3> let foo: NSString = "foo"
 foo: Foundation.NSString = \{
 Foundation.NSObject = \{}
 _cfinfo =

\{ info = 1920 pad = 0 }

_storage = "foo"
 }
 4> let bar = foo as String
 repl.swift:4:11: error: cannot convert value of type 'NSString' to type 'String' in coercion
 let bar = foo as String
 ^~~

While on OS X, it will do as expected:

3> let foo:NSString = "foo"
 foo: NSString = "foo"
 4> let bar = foo as String
 bar: String = "foo"

In order for the Linux version of Swift-repl to recognize Foundation, it needs to be invoked as follows:

%: swift -lFoundation <rest of the parameters>

This tells Swift that you're using Foundation and to link (-l) with the Foundation shared library. However, this is not needed on OS X.

Feel free to contact me if you have any questions,

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions