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

Commit

Permalink
Merge pull request #10 from realm-demos/mt/swift4-cocoa3
Browse files Browse the repository at this point in the history
[WIP] Swift 4 / RealmSwift 3 update
  • Loading branch information
icanzilb authored Oct 17, 2017
2 parents 179e0d7 + fae99aa commit 111aa25
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 37 deletions.
15 changes: 14 additions & 1 deletion Example/Podfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use_frameworks!

target 'RealmContent_Example' do
pod 'RealmSwift'
pod 'RealmSwift', '~> 3'

pod 'RealmContent', :path => '../'
pod 'RealmContent/Markdown', :path => '../'
Expand All @@ -10,3 +10,16 @@ target 'RealmContent_Example' do
inherit! :search_paths
end
end

post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
next unless target.name.include?("RealmSwift") ||
target.name.include?("Kingfisher") ||
target.name.include?("MMMarkdown") ||
target.name.include?("RealmContent")

config.build_settings['SWIFT_VERSION'] = '4.0'
end
end
end
22 changes: 17 additions & 5 deletions Example/RealmContent.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0720;
LastUpgradeCheck = 0820;
LastUpgradeCheck = 0900;
ORGANIZATIONNAME = CocoaPods;
TargetAttributes = {
607FACCF1AFB9204008FA782 = {
Expand Down Expand Up @@ -503,14 +503,20 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand Down Expand Up @@ -550,14 +556,20 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand Down Expand Up @@ -595,7 +607,7 @@
MODULE_NAME = ExampleApp;
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand All @@ -612,7 +624,7 @@
MODULE_NAME = ExampleApp;
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand All @@ -633,7 +645,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand All @@ -650,7 +662,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0820"
LastUpgradeVersion = "0900"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down Expand Up @@ -40,6 +40,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
Expand Down Expand Up @@ -69,6 +70,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
8 changes: 4 additions & 4 deletions Example/RealmContent/Entities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import Foundation
import RealmSwift

class Dog: Object {
dynamic var name = ""
dynamic var age = 0
@objc dynamic var name = ""
@objc dynamic var age = 0
}

class Person: Object {
dynamic var name = ""
dynamic var picture: NSData? = nil
@objc dynamic var name = ""
@objc dynamic var picture: NSData? = nil
let dogs = List<Dog>()
}
8 changes: 5 additions & 3 deletions RealmContent.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'RealmContent'
s.version = '0.2.3'
s.version = '0.2.4'
s.summary = 'Realm powered content management system'

s.description = <<-DESC
Expand All @@ -21,8 +21,8 @@ Realm powered content management system providing built-in view controllers and

s.frameworks = 'UIKit'

s.dependency 'RealmSwift', '~> 2'
s.dependency 'Kingfisher', '~> 3'
s.dependency 'RealmSwift', '~> 3'
s.dependency 'Kingfisher', '~> 4'
s.dependency 'NSString+Color'

s.default_subspec = 'Core'
Expand All @@ -36,4 +36,6 @@ Realm powered content management system providing built-in view controllers and

cs.source_files = 'RealmContent/Entities/*', 'RealmContent/Markdown/Classes/*', 'RealmContent/Markdown/View/*'
end

s.pod_target_xcconfig = { 'SWIFT_VERSION' => '4.0' }
end
4 changes: 2 additions & 2 deletions RealmContent/Core/Classes/ContentListDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public class ContentListDataSource: NSObject {
// sort the pages by priority
results = results!.sorted(byKeyPath: keyPriority, ascending: false)

resultsToken = results?.addNotificationBlock { [weak self] change in
resultsToken = results?.observe { [weak self] change in
guard let view = self?.view else { return }
if let tableView = view as? UITableView { tableView.reloadData() }
if let collectionView = view as? UICollectionView { collectionView.reloadData() }
Expand All @@ -124,7 +124,7 @@ public class ContentListDataSource: NSObject {
SortDescriptor(keyPath: keyPriority, ascending: false)
])

resultsToken = results?.addNotificationBlock { [weak self] change in
resultsToken = results?.observe { [weak self] change in
guard let this = self else { return }

switch change {
Expand Down
8 changes: 4 additions & 4 deletions RealmContent/Core/View/ContentViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@ public class ContentViewController: UIViewController, UITableViewDataSource, UIT
}

private func observe(page: ContentPage) {
pageUpdatesToken?.stop()
pageElementsUpdatesToken?.stop()
pageUpdatesToken?.invalidate()
pageElementsUpdatesToken?.invalidate()

// load the page content
populateFrom(page: page)

// enable updates
pageUpdatesToken = page.addNotificationBlock() { [weak self] change in
pageUpdatesToken = page.observe() { [weak self] change in
switch change {
case .change(let properties):
for p in properties {
Expand All @@ -112,7 +112,7 @@ public class ContentViewController: UIViewController, UITableViewDataSource, UIT

pageElementsUpdatesToken = page.elements
.filter(NSPredicate(format: "type in %@", ContentElement.Kind.allRawValues()))
.addNotificationBlock(applyChanges)
.observe(applyChanges)
}

private func populateFrom(page: ContentPage) {
Expand Down
4 changes: 2 additions & 2 deletions RealmContent/Core/View/ImageContentCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class ImageContentCell: UITableViewCell {
contentView.addSubview(img)

heightConstraint = contentView.heightAnchor.constraint(equalToConstant: 20)
heightConstraint.priority = 500
heightConstraint.priority = UILayoutPriority.defaultLow
heightConstraint.isActive = true
}

Expand Down Expand Up @@ -124,7 +124,7 @@ public class ImageContentCell: UITableViewCell {
return image
}

internal func didTap() {
@objc internal func didTap() {
guard let url = url else { return }
img.alpha = 0.67
UIView.animate(withDuration: 0.33, animations: {
Expand Down
2 changes: 1 addition & 1 deletion RealmContent/Core/View/TextContentCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public class TextContentCell: UITableViewCell {

// MARK: - private methods

internal func didTap() {
@objc internal func didTap() {
guard let url = url else { return }
label.alpha = 0.5
UIView.animate(withDuration: 0.33, animations: {
Expand Down
7 changes: 3 additions & 4 deletions RealmContent/Entities/ContentElement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ public class ContentElement: Object {
}


public dynamic var type = "p"
public dynamic var content = ""
public dynamic var url: String?

@objc public dynamic var type = "p"
@objc public dynamic var content = ""
@objc public dynamic var url: String?
}

extension ContentElement {
Expand Down
12 changes: 6 additions & 6 deletions RealmContent/Entities/ContentPage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import RealmSwift
/// represents a single content page - news article, blog post, announcement, etc.
public class ContentPage: Object {

public dynamic var title: String?
@objc public dynamic var title: String?
public let elements = List<ContentElement>()
public dynamic var priority = 0
public dynamic var mainColor: String?
public dynamic var lang: String?
public dynamic var tag = ""
public dynamic var uuid = UUID().uuidString
@objc public dynamic var priority = 0
@objc public dynamic var mainColor: String?
@objc public dynamic var lang: String?
@objc public dynamic var tag = ""
@objc public dynamic var uuid = UUID().uuidString

override public static func indexedProperties() -> [String] {
return ["priority", "tag"]
Expand Down
8 changes: 4 additions & 4 deletions RealmContent/Markdown/View/MarkdownViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,22 @@ public class MarkdownViewController: UIViewController {

// dynamically update the content
private func observe(page: ContentPage) {
pageUpdatesToken?.stop()
pageElementsUpdatesToken?.stop()
pageUpdatesToken?.invalidate()
pageElementsUpdatesToken?.invalidate()

// load the page content
populateFrom(page: page)

// enable updates
pageUpdatesToken = page.addNotificationBlock { [weak self] change in
pageUpdatesToken = page.observe { [weak self] change in
switch change {
case .change: self?.populateFrom(page: page)
case .deleted: self?.pageUpdatesToken = nil
default: break
}
}

pageElementsUpdatesToken = page.elements.addNotificationBlock { [weak self] change in
pageElementsUpdatesToken = page.elements.observe { [weak self] change in
switch change {
case .update: self?.populateFrom(page: page)
default: break
Expand Down

0 comments on commit 111aa25

Please sign in to comment.