Skip to content
This repository has been archived by the owner on Nov 2, 2019. It is now read-only.

Commit

Permalink
Update for Xcode 9 and Swift 4 (#184)
Browse files Browse the repository at this point in the history
* Deprecate fields in FBSDKLinkShareContent

The title, description, and imageURL fields are deprecated for LinkShareContent in in Graph API 2.9

* Update xcconfig files to Swift 4

Changing SWIFT_VERSION to 4.0 for FacebookCore, FacebookShare, FacebookLogin, and SwiftCatalog

* Fix deprecated .toUIntMax references

Replacing deprecated usages of .toUIntMax() in AppEvent and AppInvite

* Update Cartfiles to facebook-ios-sdk 4.27.1

Hotfix being released for the objective-c SDK to support Xcode 9 and Swift 4

* Update Travis CI Xcode image

Updates the Xcode image used by Travis to 9

* Update Swift badge in README

Update shields Swift badge to 4.0

* Remove inaccessible default case in Permissions

Clears the warning that ReadPermission and PublishPermission both have a default case which will never be executed.

* Remove redundant conformance constraint

Remove redundant conformance constraints from GraphRequestConnection

* Remove redundant conformance constraint

Remove redundant conformance constraint from GraphAPIReadViewController

* Update .swift-version to 4.0

Update .swift-version to 4.0
  • Loading branch information
gfosco authored Oct 11, 2017
1 parent db60b99 commit 219dc71
Show file tree
Hide file tree
Showing 18 changed files with 45 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.1
4.0
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ branches:
- master
language: objective-c
os: osx
osx_image: xcode8.3
osx_image: xcode9
cache:
- cocoapods
env:
Expand Down
2 changes: 1 addition & 1 deletion Cartfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
github "facebook/facebook-ios-sdk" ~> 4.16
github "facebook/facebook-ios-sdk" ~> 4.27.1
2 changes: 1 addition & 1 deletion Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
github "BoltsFramework/Bolts-ObjC" "1.8.4"
github "facebook/facebook-ios-sdk" "sdk-version-4.21.0"
github "facebook/facebook-ios-sdk" "sdk-version-4.27.1"
2 changes: 1 addition & 1 deletion Configurations/FacebookCore.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
PRODUCT_NAME = FacebookCore
PRODUCT_BUNDLE_IDENTIFIER = com.facebook.swift.core

SWIFT_VERSION = 3.0
SWIFT_VERSION = 4.0

IPHONEOS_DEPLOYMENT_TARGET = 8.0

Expand Down
2 changes: 1 addition & 1 deletion Configurations/FacebookLogin.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
PRODUCT_NAME = FacebookLogin
PRODUCT_BUNDLE_IDENTIFIER = com.facebook.swift.login

SWIFT_VERSION = 3.0
SWIFT_VERSION = 4.0

IPHONEOS_DEPLOYMENT_TARGET = 8.0

Expand Down
2 changes: 1 addition & 1 deletion Configurations/FacebookShare.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
PRODUCT_NAME = FacebookShare
PRODUCT_BUNDLE_IDENTIFIER = com.facebook.swift.share

SWIFT_VERSION = 3.0
SWIFT_VERSION = 4.0

IPHONEOS_DEPLOYMENT_TARGET = 8.0

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Facebook SDK in Swift (Beta)

[![Platforms](https://img.shields.io/cocoapods/p/FacebookCore.svg)]()
[![Swift Version](https://img.shields.io/badge/Swift-3.0.x-orange.svg)]()
[![Swift Version](https://img.shields.io/badge/Swift-4.0.x-orange.svg)]()
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)]()

[![Build Status](https://img.shields.io/travis/facebook/facebook-sdk-swift/master.svg?style=flat)](https://travis-ci.org/facebook/facebook-sdk-swift)
Expand Down
2 changes: 1 addition & 1 deletion Samples/Catalog/Configurations/SwiftCatalog.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.facebook.SwiftCatalog
CODE_SIGN_IDENTITY = iPhone Developer
CODE_SIGN_ENTITLEMENTS = Resources/SwiftCatalog.entitlements

SWIFT_VERSION = 3.0
SWIFT_VERSION = 4.0

IPHONEOS_DEPLOYMENT_TARGET = 8.0

Expand Down
2 changes: 1 addition & 1 deletion Samples/Catalog/Sources/GraphAPIReadViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import FacebookCore

class GraphAPIReadViewController: UITableViewController {

func presentAlertControllerFor<P: GraphRequestProtocol>(_ result: GraphRequestResult<P>) {
func presentAlertControllerFor<P>(_ result: GraphRequestResult<P>) {
let alertController: UIAlertController
switch result {
case .success(let response):
Expand Down
6 changes: 2 additions & 4 deletions Samples/Catalog/Sources/ShareAPIViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,8 @@ final class ShareAPIViewController: UITableViewController {

extension ShareAPIViewController {
@IBAction func shareLink() {
let content = LinkShareContent(url: URL(string: "https://newsroom.fb.com/")!,
title: "Name: Facebook News Room",
description: "Description: The Facebook Swift SDK helps you develop Facebook integrated iOS apps.",
imageURL: URL(string: "https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png"))
let url = URL(string: "https://newsroom.fb.com/")
let content = LinkShareContent(url: url!)
share(content)
}
}
Expand Down
14 changes: 5 additions & 9 deletions Samples/Catalog/Sources/ShareDialogViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,8 @@ final class ShareDialogViewController: UITableViewController {

extension ShareDialogViewController {
@IBAction func showLinkShareDialogModeAutomatic() {
var content = LinkShareContent(url: URL(string: "https://newsroom.fb.com/")!,
title: "Name: Facebook News Room",
description: "Description: The Facebook Swift SDK helps you develop Facebook integrated iOS apps.",
imageURL: URL(string: "https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png"))
let url = URL(string: "https://newsroom.fb.com/")
var content = LinkShareContent(url: url!)

// placeId is hardcoded here, see https://developers.facebook.com/docs/graph-api/using-graph-api/#search for building a place picker.
content.placeId = "166793820034304"
Expand All @@ -54,11 +52,9 @@ extension ShareDialogViewController {
}

@IBAction func showLinkShareDialogModeWeb() {
var content = LinkShareContent(url: URL(string: "https://newsroom.fb.com/")!,
title: "Name: Facebook News Room",
description: "Description: The Facebook Swift SDK helps you develop Facebook integrated iOS apps.",
imageURL: URL(string: "https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png"))

let url = URL(string: "https://newsroom.fb.com/")
var content = LinkShareContent(url: url!)

// placeId is hardcoded here, see https://developers.facebook.com/docs/graph-api/using-graph-api/#search for building a place picker.
content.placeId = "166793820034304"

Expand Down
4 changes: 2 additions & 2 deletions Sources/Core/AppEvents/AppEvent.Builtin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ extension AppEvent {
var parameters = extraParameters
contentType.onSome({ parameters[.contentType] = $0 })
contentId.onSome({ parameters[.contentId] = $0 })
maxRatingValue.onSome({ parameters[.maxRatingValue] = NSNumber(value: $0.toUIntMax() as UInt64) })
maxRatingValue.onSome({ parameters[.maxRatingValue] = NSNumber(value: UInt64($0)) })
return AppEvent(name: .rated, parameters: parameters, valueToSum: valueToSum)
}
}
Expand Down Expand Up @@ -236,7 +236,7 @@ extension AppEvent {
var parameters = extraParameters
contentType.onSome({ parameters[.contentType] = $0 })
contentId.onSome({ parameters[.contentId] = $0 })
itemCount.onSome({ parameters[.itemCount] = NSNumber(value: $0.toUIntMax() as UInt64) })
itemCount.onSome({ parameters[.itemCount] = NSNumber(value: UInt64($0)) })
paymentInfoAvailable.onSome({
parameters[.paymentInfoAvailable] = $0 ? FBSDKAppEventParameterValueYes : FBSDKAppEventParameterValueNo
})
Expand Down
6 changes: 3 additions & 3 deletions Sources/Core/GraphRequest/GraphRequestConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ extension GraphRequestConnection {
As described in [Graph API Batch Requests](https://developers.facebook.com/docs/reference/api/batch/).
- parameter completion: Optional completion closure that is going to be called when the connection finishes or fails.
*/
public func add<T: GraphRequestProtocol>(_ request: T,
public func add<T>(_ request: T,
batchEntryName: String? = nil,
completion: Completion<T>? = nil) {
let batchParameters = batchEntryName.map({ ["name" : $0] })
Expand All @@ -102,7 +102,7 @@ extension GraphRequestConnection {
Examples include "depends_on", "name", or "omit_response_on_success".
- parameter completion: Optional completion closure that is going to be called when the connection finishes or fails.
*/
public func add<T: GraphRequestProtocol>(_ request: T,
public func add<T>(_ request: T,
batchParameters: [String : Any]?,
completion: Completion<T>? = nil) {
sdkConnection.add(request.sdkRequest,
Expand Down Expand Up @@ -139,7 +139,7 @@ extension GraphRequestConnection {
/// Custom typealias that is the same as FBSDKGraphRequestHandler, but without implicitly unwrapped optionals.
internal typealias SDKRequestCompletion = (_ connection: FBSDKGraphRequestConnection?, _ rawResponse: Any?, _ error: Error?) -> Void

internal static func sdkRequestCompletion<T: GraphRequestProtocol>(from completion: @escaping Completion<T>) -> SDKRequestCompletion {
internal static func sdkRequestCompletion<T>(from completion: @escaping Completion<T>) -> SDKRequestCompletion {
return { connection, rawResponse, error in
let result: GraphRequestResult<T> = {
switch error {
Expand Down
1 change: 0 additions & 1 deletion Sources/Core/Permissions/PublishPermission.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ extension PublishPermission: PermissionRepresentable {
case .publishPages: return "publish_pages"
case .rsvpEvent: return "rsvp_event"
case .custom(let string): return Permission(name: string)
default: return "publish_actions"
}
}
}
1 change: 0 additions & 1 deletion Sources/Core/Permissions/ReadPermission.swift
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ extension ReadPermission: PermissionRepresentable {
case .pagesManageInstantArticles: return "pages_manage_instant_articles"
case .adsRead: return "ads_read"
case .custom(let string): return Permission(name: string)
default: return "public_profile"
}
}
}
19 changes: 16 additions & 3 deletions Sources/Share/Content/Link/LinkShareContent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public struct LinkShareContent: ContentProtocol {

This value may be discarded for specially handled links (ex: iTunes URLs).
*/
@available(*, deprecated, message: "`title` is deprecated from Graph API 2.9")
public var title: String?

/**
Expand All @@ -38,6 +39,7 @@ public struct LinkShareContent: ContentProtocol {
If not specified, this field is automatically populated by information scraped from the contentURL,
typically the title of the page. This value may be discarded for specially handled links (ex: iTunes URLs).
*/
@available(*, deprecated, message: "`description` is deprecated from Graph API 2.9")
public var description: String?

/**
Expand All @@ -48,6 +50,7 @@ public struct LinkShareContent: ContentProtocol {
public var quote: String?

/// The URL of a picture to attach to this content.
@available(*, deprecated, message: "`imageURL` is deprecated from Graph API 2.9")
public var imageURL: URL?

/**
Expand All @@ -59,6 +62,7 @@ public struct LinkShareContent: ContentProtocol {
- parameter quote: Optional quote text of the link.
- parameter imageURL: OPtional image URL of a picture to attach.
*/
@available(*, deprecated, message: "`title`, `description`, `imageURL` are deprecated from Graph API 2.9")
public init(url: URL,
title: String? = nil,
description: String? = nil,
Expand All @@ -70,6 +74,18 @@ public struct LinkShareContent: ContentProtocol {
self.quote = quote
self.imageURL = imageURL
}

/**
Create link share content.

- parameter url: The URL being shared.
- parameter quote: Optional quote text of the link.
*/
public init(url: URL,
quote: String? = nil) {
self.url = url
self.quote = quote
}

//--------------------------------------
// MARK - Content
Expand Down Expand Up @@ -118,9 +134,6 @@ extension LinkShareContent: Equatable {
extension LinkShareContent: SDKBridgedContent {
internal var sdkSharingContentRepresentation: FBSDKSharingContent {
let content = FBSDKShareLinkContent()
content.contentDescription = self.description
content.contentTitle = self.title
content.imageURL = self.imageURL
content.quote = self.quote
content.contentURL = self.url
content.hashtag = self.hashtag?.sdkHashtagRepresentation
Expand Down
14 changes: 7 additions & 7 deletions Sources/Share/Dialogs/AppInvite/AppInvite.PromoCode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ extension AppInvite.PromoCode: ExpressibleByStringLiteral {
extension AppInvite.PromoCode {
fileprivate static func truncate(string: String) -> String {
let validCharacters = CharacterSet.alphanumerics
let cleaned = string.unicodeScalars.filter {
validCharacters.contains(UnicodeScalar(UInt16($0.value))!)
}

let range = 0 ..< min(10, cleaned.count)
let characters = cleaned[range].map(Character.init)
return String(characters)
let cleaned = string
.unicodeScalars
.filter({
validCharacters.contains(UnicodeScalar(UInt16($0.value))!)
})
.map(Character.init)
return String(cleaned)
}
}

0 comments on commit 219dc71

Please sign in to comment.