Swift 기반 애플리케이션은 OS X 10.9 / iOS 7 이하에서 작동합니까?
Swift 기반 애플리케이션은 OS X 10.9 (Mavericks) / iOS 7 이하에서 작동합니까?
예를 들어 OS X 10.8 (Mountain Lion)을 실행하는 컴퓨터가 있는데 Swift로 작성한 응용 프로그램이 실행되는지 궁금합니다.
방금 테스트했는데 Swift 애플리케이션은 표준 바이너리로 컴파일되며 OS X 10.9 및 iOS 7에서 실행할 수 있습니다.
테스트에 사용되는 간단한 Swift 애플리케이션 :
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
var controller = UIViewController()
var view = UIView(frame: CGRectMake(0, 0, 320, 568))
view.backgroundColor = UIColor.redColor()
controller.view = view
var label = UILabel(frame: CGRectMake(0, 0, 200, 21))
label.center = CGPointMake(160, 284)
label.textAlignment = NSTextAlignment.Center
label.text = "I'am a test label"
controller.view.addSubview(label)
self.window!.rootViewController = controller
self.window!.makeKeyAndVisible()
return true
}
Swift 코드는 OS X 10.9 및 iOS 7.0에 배포 할 수 있습니다. 일반적으로 이전 OS 버전에서 실행시 충돌합니다.
Apple은 Swift 앱이 iOS 7 및 OS X Mavericks와 역 호환 될 것이라고 발표했습니다. WWDC 앱은 Swift로 작성되었습니다.
업데이트-Xcode 6 Beta 4에 따라
iOS 7 및 OS X 10.9 최소 배포 대상
Swift 컴파일러 및 Xcode는 이제 iOS 7 또는 OS X Mavericks의 최소 배포 대상을 적용합니다. 이전 배포 대상을 설정하면 빌드 실패가 발생합니다.
따라서 이전 답변 (아래 표시)은 추가 개발에 적용되지 않습니다. Swift는 iOS6 이하에서 더 이상 사용할 수 없습니다.
Swift 애플리케이션은 iOS 6에서 실행할 수 있습니다. 많은 사람들이 Swift가 iOS 7+ 및 OS X 10.9+ 만 지원한다고 말하지만 제 경험으로는 그렇지 않습니다.
iOS 6 기기에서 Swift로 완전히 작성된 간단한 애플리케이션을 테스트했습니다. 완벽하게 잘 작동합니다 . Apple이 말했듯이 Swift 코드는 Objective-C 코드와 바이너리 호환됩니다. 동일한 컴파일러와 런타임을 사용하여 바이너리를 만듭니다.
테스트 한 코드는 다음과 같습니다.
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let button = UIButton.buttonWithType(UIButtonType.System) as UIButton
button.frame = CGRectMake(100, 100, 100, 50)
button.backgroundColor = UIColor.greenColor()
button.setTitle("Test Button", forState: UIControlState.Normal)
button.addTarget(self, action: "buttonTapped:", forControlEvents: UIControlEvents.TouchUpInside)
self.view.addSubview(button)
}
func buttonTapped(sender: UIButton!) {
println("buttonTapped")
}
}
프로그래밍 방식으로 버튼을 추가하는 간단한 응용 프로그램입니다. 내 응용 프로그램에는 두 개의 파일 AppDelegate.swift
및 ViewController.swift
.
따라서 iOS 8 SDK의 일부로 추가 된 새 API 또는 일부 Swift 특정 API (Objective-C에는 해당 API를 사용할 수 없음)를 사용하지 않는 경우 애플리케이션이 iOS 6 이상 (테스트 및 작동 중)에서도 원활하게 작동합니다. iOS 5 (테스트되지 않음). Swift의 대부분의 API는 기존 Objective-C API를 대체 한 것입니다. 사실 그들은 바이너리에서 동일합니다.
참고 : Xcode 6 베타 4에 따라 신속한 앱 배포 대상은 iOS 7 또는 OS X 10.9 여야합니다 (위 업데이트 참조). 따라서 swift는 더 이상 iOS6 이하에서 사용할 수 없습니다.
간단히 말해서 :
Swift 기반 애플리케이션은 동일한 앱을 사용 하여 OS X Mavericks 또는 iOS 7 을 다시 타겟팅 할 수 있습니다.
그게 어떻게 가능해 ?
Xcode embeds a small Swift runtime library within your app’s bundle. Because the library is embedded, your app uses a consistent version of Swift that runs on past, present, and future OS releases.
Why should I trust this answer ?
Because I am not saying this answer as one apple guy told me in twitter or I wrote hello world and tested it.
I took it from apple developer blog.
so you can trust this.
Swift uses the same runtime as Objective-C and can even live side-by-side Objective-C in the same application (as per the WWDC 2014 keynote).
This will need to be checked/verified using Xcode 6 and the new SDK to find a final answer.
I read all answers that said: No, Swift does not work with less than iOS 7. But I said YES, I just created a Swift project that does run in Xcode 5 with 6.0 deployment target.
- I just create a demo project in Xcode 6 BETA with the Swift programming language selected.
- Close Xcode 6 beta, and I open this demo project in Xcode 5 with deployment target 6.0
- And also select simulator 6.1.
Then that project runs well in simulator 6.1. My MacOS X is 10.9.3, so I said yes, that runs in lower than iOS 7. with 10.9.3 Mac OS X.
Here it is a screenshot of the simulator:
While code confirms it, Apple itself has said that Swift will be compatible on iOS 7 and Mavericks in their technical keynote (State of the platforms, session 102, around the 34 min 00 sec mark) at WWDC 2014.
Swift applications are supported on iOS 7 and above as stated in Beta 4 release notes.
iOS 6.0, 6.1, 7.0, 7.1, 8.0 in Xcode 6 Beta
Swift applications are supported on platforms OS X 10.9 and above.
OS X 10.4 to 10.10 in Deployment Target. I have tested on targeting 10.5 to 10.10, and running on 10.9.3
It appears Swift applications don't run on OS X 10.7. I just created a simple GUI application (a view, a lable, a button) which runs fine on Mavericks. The base SDK is set to 10.9 and the deployment target to 10.7. I copied that application from the DerivedData folder over to my 10.7 virtual machine, and it crashs when starting, show this error:
Crashed Thread: 0
Exception Type: EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000002, 0x0000000000000000
Application Specific Information:
dyld: launch, loading dependent libraries
Dyld Error Message:
Library not loaded: /System/Library/Frameworks/CoreGraphics.framework/Versions/A/CoreGraphics
Referenced from: /Users/USER/Desktop/Swift-Test.app/Contents/MacOS/../Frameworks/libswiftAppKit.dylib
Reason: image not found
Binary Images:
0x109c65000 - 0x109c6afff +private.Swift-Test (1.0 - 1) <649695D0-58FD-3D02-9176-2D40D4E711F2> /Users/USER/Desktop/Swift-Test.app/Contents/MacOS/Swift-Test
0x109c83000 - 0x109dbffff +libswift_stdlib_core.dylib (1.0 - 600.0.34.4.5) <10AAC369-9404-321D-A892-49F65856D7AF> /Users/USER/Desktop/Swift-Test.app/Contents/Frameworks/libswift_stdlib_core.dylib
...
However this message is irritating, since there's certainly a CoreGraphics library in this VM. Other applications that make heavy use of CoreGraphics work just fine.
This is the post I read from apple Swift blog, might be helpful:
App Compatibility:
If you write a Swift app you can trust that your app will work well into the future. In fact, you can target back to OS X Mavericks or iOS 7 with that same app. This is possible because Xcode embeds a small Swift runtime library within your app's bundle. Because the library is embedded, your app uses a consistent version of Swift that runs on past, present, and future OS releases.
Binary Compatibility and Frameworks:
While your app's runtime compatibility is ensured, the Swift language itself will continue to evolve, and the binary interface will also change. To be safe, all components of your app should be built with the same version of Xcode and the Swift compiler to ensure that they work together.
This means that frameworks need to be managed carefully. For instance, if your project uses frameworks to share code with an embedded extension, you will want to build the frameworks, app, and extensions together. It would be dangerous to rely upon binary frameworks that use Swift — especially from third parties. As Swift changes, those frameworks will be incompatible with the rest of your app. When the binary interface stabilizes in a year or two, the Swift runtime will become part of the host OS and this limitation will no longer exist.
I tested running a bare-bone, Swift-based app on an iPod Touch (3rd gen) device. It appears Swift-based apps don't work with iOS 5.x but do work with iOS 6.x.
Here's what shows up in the debug log when I tried to launch the test app with iOS 5.0.1:
dyld: F_ADDFILESIGS failed for /private/var/mobile/Applications/59E31E79-9525-43B0-9DF6-8FEF3C0080F1/SwiftTestApp.app/Frameworks/libswift_stdlib_core.dylib with errno=1
dyld: F_ADDFILESIGS failed for /private/var/mobile/Applications/59E31E79-9525-43B0-9DF6-8FEF3C0080F1/SwiftTestApp.app/Frameworks/libswiftCoreGraphics.dylib with errno=1
dyld: F_ADDFILESIGS failed for /private/var/mobile/Applications/59E31E79-9525-43B0-9DF6-8FEF3C0080F1/SwiftTestApp.app/Frameworks/libswiftDarwin.dylib with errno=1
dyld: F_ADDFILESIGS failed for /private/var/mobile/Applications/59E31E79-9525-43B0-9DF6-8FEF3C0080F1/SwiftTestApp.app/Frameworks/libswiftDispatch.dylib with errno=1
dyld: F_ADDFILESIGS failed for /private/var/mobile/Applications/59E31E79-9525-43B0-9DF6-8FEF3C0080F1/SwiftTestApp.app/Frameworks/libswiftFoundation.dylib with errno=1
dyld: F_ADDFILESIGS failed for /private/var/mobile/Applications/59E31E79-9525-43B0-9DF6-8FEF3C0080F1/SwiftTestApp.app/Frameworks/libswiftObjectiveC.dylib with errno=1
dyld: F_ADDFILESIGS failed for /private/var/mobile/Applications/59E31E79-9525-43B0-9DF6-8FEF3C0080F1/SwiftTestApp.app/Frameworks/libswiftUIKit.dylib with errno=1
dyld: Symbol not found: _OBJC_CLASS_$_NSObject
Referenced from: /private/var/mobile/Applications/59E31E79-9525-43B0-9DF6-8FEF3C0080F1/SwiftTestApp.app/Frameworks/libswift_stdlib_core.dylib
Expected in: /usr/lib/libobjc.A.dylib
in /private/var/mobile/Applications/59E31E79-9525-43B0-9DF6-8FEF3C0080F1/SwiftTestApp.app/Frameworks/libswift_stdlib_core.dylib
For iOS 6.1.6, the app runs fine without displaying those error messages.
There seems to be a lot of old answers here so I just wanted to post the official response from the Swift team. Swift is backwards compatible with OS X Mavericks and iOS 7
Apple developer swift blog : Objective-C id as Swift Any
Jul 11, 2014
Compatibility
One of the most common questions we heard at WWDC was, “What is the compatibility story for Swift?”. This seems like a great first topic.
App Compatibility Simply put, if you write a Swift app today and submit it to the App Store this Fall when iOS 8 and OS X Yosemite are released, you can trust that your app will work well into the future. In fact, you can target back to OS X Mavericks or iOS 7 with that same app. This is possible because Xcode embeds a small Swift runtime library within your app’s bundle. Because the library is embedded, your app uses a consistent version of Swift that runs on past, present, and future OS releases.
I also tried a very simple app on 10.8 (one button, sets text on a label). It crashed at startup, as Greg Parker stated:
Dyld Error Message:
Symbol not found: __dispatch_source_type_memorypressure
Referenced from: /Volumes/*/SwifTest.app/Contents/MacOS/../Frameworks/libswiftDispatch.dylib
Expected in: /usr/lib/libSystem.B.dylib
in /Volumes/*/SwifTest.app/Contents/MacOS/../Frameworks/libswiftDispatch.dylib
(This was using a deployment target of 10.7)
Try the following code:
It's working without StoryBoard:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
self.window!.backgroundColor = UIColor.whiteColor()
// Create a nav/vc pair using the custom ViewController class
let nav = UINavigationController()
let vc = ViewController(nibName: "ViewController", bundle: nil)
// Push the vc onto the nav
nav.pushViewController(vc, animated: false)
// Set the window’s root view controller
self.window!.rootViewController = nav
// Present the window
self.window!.makeKeyAndVisible()
return true
}
Yes, in fact Apple has announced that Swift apps will be backward compatible with iOS 7 and OS X Mavericks. Furthermore the WWDC app is written in the Swift programming language.
When it comes to Swift Frameworks. As for today, with Xcode version 6.1.1 (6A2008a), if the Swift framework is targeted to iOS 7.1, linker report warning
ld: warning: embedded dylibs/frameworks only run on iOS 8 or later.
and application can't be submitted to AppStore. Check this issue : Lint to prevent dynamic libraries and frameworks from passing with iOS 7
Quick Update, effective from February 15th, 2015, we cannot submit apps to the store that were developed using an SDK prior to iOS 8. So, keeping that in mind , its better to not to worry about this issue as many people have suggested that apps made in Swift can be deployed to OS X 10.9 and iOS 7.0 as well.
Answered code-snippet posted by Leandros seems bit old. I have fixed and made it compilable in Swift 5.
Swift 5
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
self.window = UIWindow(frame: UIScreen.main.bounds)
let controller = UIViewController()
let view = UIView(frame: CGRect(x: 0, y: 0, width: 320, height: 568))
view.backgroundColor = UIColor.red
controller.view = view
let label = UILabel(frame: CGRect(x: 0, y: 0, width: 200, height: 21))
label.center = CGPoint(x: 160, y: 284)
label.textAlignment = NSTextAlignment.center
label.text = "I'am a test label"
controller.view.addSubview(label)
self.window!.rootViewController = controller
self.window!.makeKeyAndVisible()
return true
}
'Program Tip' 카테고리의 다른 글
C # 인터페이스. (0) | 2020.10.02 |
---|---|
수정 된 커밋을 원격 Git 저장소에 푸시하려면 어떻게해야합니까? (0) | 2020.10.02 |
Cygwin과 MinGW의 차이점은 무엇입니까? (0) | 2020.10.02 |
스택 추적이란 무엇이며 애플리케이션 오류를 디버그하는 데 어떻게 사용할 수 있습니까? (0) | 2020.10.02 |
파이썬에서 __future__는 무엇에 사용되며 어떻게 / 언제 사용되며 어떻게 작동하는지 (0) | 2020.10.02 |