Skip to content

Commit

Permalink
RatingView is now usable from ObjC, fixed error with initWithFrame me…
Browse files Browse the repository at this point in the history
…thod

delegate property is weak now
  • Loading branch information
Peter Prokop committed Nov 26, 2015
1 parent d1fb986 commit 5b6e495
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 2 deletions.
6 changes: 4 additions & 2 deletions StarryStars/RatingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import UIKit

public protocol RatingViewDelegate {
@objc public protocol RatingViewDelegate {
/**
Called when user's touch ends
Expand Down Expand Up @@ -53,13 +53,15 @@ public class RatingView: UIView {


/// Delegate, must confrom to *RatingViewDelegate* protocol
@IBInspectable public var delegate: RatingViewDelegate?
public weak var delegate: RatingViewDelegate?

var stars = [UIImageView]()


override init(frame: CGRect) {
super.init(frame: frame)

customInit()
}

required public init?(coder aDecoder: NSCoder) {
Expand Down
14 changes: 14 additions & 0 deletions StarryStarsExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
0D04DE721C07009700EBDC42 /* ObjCViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 0D04DE711C07009700EBDC42 /* ObjCViewController.m */; };
0D2DE7131BE5F23E005DBFEC /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D2DE7091BE5F23E005DBFEC /* AppDelegate.swift */; };
0D2DE7151BE5F23E005DBFEC /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 0D2DE70B1BE5F23E005DBFEC /* LaunchScreen.storyboard */; };
0D2DE7161BE5F23E005DBFEC /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 0D2DE70D1BE5F23E005DBFEC /* Main.storyboard */; };
Expand All @@ -18,6 +19,9 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
0D04DE6C1C07006F00EBDC42 /* StarryStarsExample-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "StarryStarsExample-Bridging-Header.h"; sourceTree = "<group>"; };
0D04DE701C07009700EBDC42 /* ObjCViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ObjCViewController.h; sourceTree = "<group>"; };
0D04DE711C07009700EBDC42 /* ObjCViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ObjCViewController.m; sourceTree = "<group>"; };
0D2DE7091BE5F23E005DBFEC /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
0D2DE70C1BE5F23E005DBFEC /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
0D2DE70E1BE5F23E005DBFEC /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
Expand Down Expand Up @@ -49,6 +53,9 @@
0D2DE70D1BE5F23E005DBFEC /* Main.storyboard */,
0D2DE70F1BE5F23E005DBFEC /* Info.plist */,
0D2DE7121BE5F23E005DBFEC /* ViewController.swift */,
0D04DE6C1C07006F00EBDC42 /* StarryStarsExample-Bridging-Header.h */,
0D04DE701C07009700EBDC42 /* ObjCViewController.h */,
0D04DE711C07009700EBDC42 /* ObjCViewController.m */,
);
path = StarryStarsExample;
sourceTree = "<group>";
Expand Down Expand Up @@ -115,6 +122,7 @@
0DEBD3931BDA134D00FC7856 /* Project object */ = {
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0710;
LastUpgradeCheck = 0700;
ORGANIZATIONNAME = "Peter Prokop";
TargetAttributes = {
Expand Down Expand Up @@ -161,6 +169,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
0D04DE721C07009700EBDC42 /* ObjCViewController.m in Sources */,
0D2DE7201BE5F83C005DBFEC /* RatingView.swift in Sources */,
0D2DE7191BE5F23E005DBFEC /* ViewController.swift in Sources */,
0D2DE7131BE5F23E005DBFEC /* AppDelegate.swift in Sources */,
Expand Down Expand Up @@ -274,21 +283,26 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
INFOPLIST_FILE = StarryStarsExample/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = Prokop.StarryStarsExample;
PRODUCT_NAME = StarryStarsExample;
SWIFT_OBJC_BRIDGING_HEADER = "StarryStarsExample/StarryStarsExample-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
};
name = Debug;
};
0DEBD3AF1BDA134D00FC7856 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
INFOPLIST_FILE = StarryStarsExample/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = Prokop.StarryStarsExample;
PRODUCT_NAME = StarryStarsExample;
SWIFT_OBJC_BRIDGING_HEADER = "StarryStarsExample/StarryStarsExample-Bridging-Header.h";
};
name = Release;
};
Expand Down
20 changes: 20 additions & 0 deletions StarryStarsExample/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,25 @@
</objects>
<point key="canvasLocation" x="296" y="391"/>
</scene>
<!--ObjC View Controller-->
<scene sceneID="P4P-Md-zok">
<objects>
<viewController id="cCr-Cx-7vq" customClass="ObjCViewController" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="1y5-ap-t4D"/>
<viewControllerLayoutGuide type="bottom" id="e3g-18-k7R"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="J9V-zL-MSi">
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<animations/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</view>
<simulatedScreenMetrics key="simulatedDestinationMetrics" type="retina4"/>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="8xE-XA-3Zf" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="753" y="391"/>
</scene>
</scenes>
</document>
13 changes: 13 additions & 0 deletions StarryStarsExample/ObjCViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// ObjCViewController.h
// StarryStarsExample
//
// Created by Peter Prokop on 26/11/15.
// Copyright © 2015 Peter Prokop. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface ObjCViewController : UIViewController

@end
37 changes: 37 additions & 0 deletions StarryStarsExample/ObjCViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// ObjCViewController.m
// StarryStarsExample
//
// Created by Peter Prokop on 26/11/15.
// Copyright © 2015 Peter Prokop. All rights reserved.
//

#import "ObjCViewController.h"
#import "StarryStarsExample-Swift.h"

@interface ObjCViewController()<RatingViewDelegate>

@end

@implementation ObjCViewController

- (void)viewDidLoad {
[super viewDidLoad];


RatingView* rv = [[RatingView alloc] initWithFrame:self.view.bounds];
[self.view addSubview:rv];
rv.editable = YES;
rv.delegate = self;
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}

- (void)ratingView:(RatingView * __nonnull)ratingView didChangeRating:(float)newRating {
NSLog(@"newRating: %f", newRating);
}


@end
4 changes: 4 additions & 0 deletions StarryStarsExample/StarryStarsExample-Bridging-Header.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
//
// Use this file to import your target's public headers that you would like to expose to Swift.
//

0 comments on commit 5b6e495

Please sign in to comment.