Need job

Looking for job in Europe. Please contact thru LinkedIn profile.

Wednesday, November 29, 2017

Text kern/letter spacing in Xcode Interface builder

Sometimes designers uses different kern, not default.
How to change it with minimal time?
Add inspectable text attribute.

Here is ready-to-use code for UIButton.
Very easy transformable to UILabel.

extension UIButton {

    @IBInspectable
    var letterSpace: CGFloat {
        set {
            let attributedString: NSMutableAttributedString!
            if let currentAttrString = attributedTitle(for: .normal) {
                attributedString = NSMutableAttributedString(attributedString: currentAttrString)
            }
            else {
                attributedString = NSMutableAttributedString(string: self.titleLabel?.text ?? "")
                setTitle(.none, for: .normal)
            }

            attributedString.addAttribute(NSKernAttributeName,
                                           value: newValue,
                                           range: NSRange(location: 0, length: attributedString.length))

            setAttributedTitle(attributedString, for: .normal)
        }

        get {
            if let currentLetterSpace = attributedTitle(for: .normal)?.attribute(NSKernAttributeName, at: 0, effectiveRange: .none) as? CGFloat {
                return currentLetterSpace
            }
            else {
                return 0
            }
        }
    }
}

Thursday, February 9, 2017

Swift weak delegate

When you need to declare weak delegate property you may caught " 'weak' may only be applied to class and class-bound protocol types, not 'SwipePickerDelegate'".


Apple mentioned this in docs here:
https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Protocols.html#//apple_ref/doc/uid/TP40014097-CH25-ID281

So, all you need is add "class" keyword to protocol.


Tuesday, January 31, 2017

Couldn't create mapping policy for class named () - Core Data migration error

Its easy to fix it.
One of possible reasons is Policy class name w/o namespace.
On the image below a PRODUCT_MODULE_NAME mentioned with red.


If you don't now the name, here is the trick to find out.


Thursday, February 25, 2016

To fill any image with color

@implementation UIImageView (Utils)

- (void)setImageRenderingMode:(UIImageRenderingMode)mode
{
    if (self.image)
    {
        UIImage* newImage = [self.image imageWithRenderingMode:mode];
        [self setImage:newImage];
    }
}

- (void)fillWithColor:(UIColor*)color
{
    [self setImageRenderingMode:UIImageRenderingModeAlwaysTemplate];
    self.tintColor = color;
}

@end

Tuesday, March 31, 2015

useful localizable category for NSString

"Just code post"

@implementation NSString (Localizable)

- (NSString *)Localizable
{
    return NSLocalizedString(self, nil);

}


Using like this

NSString *newTitle = [@"settingsBarTitle" Localizable];

Tuesday, October 14, 2014

iAd error on iPad


Recently, when I was testing iAd app on iPad, I've got an error when accessing root view.
EXC_BAD_ACCESS code=2




Stack trace was looped infinitely.



We need to analyse the algorithm and change it to prevent call [self view] from error method of iAd delegate.

In my case it was easy:
During UI load my iAd banner already hidden.
I just check if banner is hidden and do nothing.

Here is a link to my post on stackoverflow - http://stackoverflow.com/questions/16471240/using-iads-on-ipad-crashes-after-huge-number-of-calls-to-bannerviewdidfailtorec/26025212#26025212











Friday, July 18, 2014

Xcode auto layout - how to fill removed control space automatically

How to automatically transform picture 1 to pic 2?

pic 1
pic 2

Its all about constraint priority and redundancy.
Priority of space between grey and blue element is higher that grey and bottom of screen.

 

Now if remove blue you will get Pic 2 scene.

Thursday, April 3, 2014

How to use UIRefreshControl without UITableViewController

Exact problem is - How to use static ui elements with table and refresh control.
All you need is storyboard)
This can be achieved with Container view.

The result is:

Monday, March 17, 2014

Objective-C deprecated method mark

Its very useful for big or distributed teams.
To achieve this:

you need to edit the declaration of method to:

- (BOOL)loginComplexWith:(NSArray*)loginTypes andDelegate:(id<LoginComplexDelegate>)delegate __attribute__ ((deprecated));

or you can use DEPRECATED_ATTRIBUTE from <AvailabilityMacros.h>

Thursday, November 14, 2013

How to hide keyboard without first responder

In any place call:
[self.view endEditing:true];
will hide keyboard. 

So, result the same as you call [sender resignFirstResponder] but in this case you need an object or you need to find him.

Friday, August 23, 2013

UITableView custom Separator Insets workaround

Hello everybody.
Here is a workaround when you try to set custom separator insets thru IB in Xcode Version 5.0 (5A11365j).
If you try, you will get:
Exception while running ibtool: *** -[NSKeyedArchiver encodeValueOfObjCType:at:]: this archiver cannot encode structs

Fix with coding:

UIEdgeInsets edges;
edges.left = 0;
tableTripPoints.separatorInset = edges;

Thursday, August 15, 2013

How to change "Placeholder" text colour for UITextField

You need to assign colour for key path "_placeholderLabel.textColor" in User defined runtime attributes.
Its simple and "no coding".


Wednesday, August 14, 2013

Make view controller transparent

You need to place a view controller in to "Container view".
Its new iOS 6 control.
Then you just need to change an alpha to desired value.
Thats it!

Thursday, July 4, 2013

Powershell remote .NET assembly deploy to GAC

If you need to deploy something to remote iis server by coping assemblies, here is a script. 
In my case i have a hyper-v sharepoint 2013 for development. 
I can compile, deploy and debug remotely.

To copy files you can use another post from this blog.

$s = New-PSSession -computerName someserverHostname.ru
Invoke-Command -Session $s -Scriptblock {
    $gacUtil = "${Env:ProgramFiles(x86)}\NETFX 4.0 Tools\gacutil.exe";
    $filesOnServer = Get-ChildItem C:\folderNameOnServer  -Recurse | Where-Object {$_.name -like '*.dll'}  | Select-Object fullname
    $filesOnServer  | % {
        & $gacUtil '/nologo' '/if' $_.fullname;
        $_.fullname;
    }
    iisreset;
;}
Remove-PSSession $s

Wednesday, April 24, 2013

Sharepoint REST with cyrillic column names

To use link like that {site}/_vti_bin/listdata.svc/{list}?$filter=Название eq 'London'
you need to encode cyrillic word.
Here is a service to do it http://meyerweb.com/eric/tools/dencoder/

Proper link is {site}/_vti_bin/listdata.svc/{list}?$filter=%D0%9D%D0%B0%D0%B7%D0%B2%D0%B0%D0%BD%D0%B8%D0%B5 eq 'London'

Thursday, February 21, 2013

Remote upgrade Sharepoint solution with PowerShell

Hello everybody!
Here is a script to upgrade Sharepoint solution on remote server.
U need to allow the remote powershell on the server.
U can replace the sriptblock with any commands. For example Add-Solution)

net use W: /delete
net use W: \\serverName\C$\folder
copy "C:\Users\user\Documents\Visual Studio 2012\Projects\Project\bin\Debug\Project.wsp" W:\
$s = New-PSSession -computerName serverName
Invoke-Command -Session $s -Scriptblock {Add-PSSnapin Microsoft.SharePoint.Powershell;Update-SPSolution -Identity Project.wsp -LiteralPath c:\folder\Project.wsp -GACDeployment}
Remove-PSSession $s

Monday, February 18, 2013

SPItemEventReceiver invoke source detection

How to detect who has update item? User from web browser or web service?
The solution is to store "Label" in thread data slot.
Sync receivers like Adding and Updating executes in the same thread as update code, in my case is web service.

Update Ready-to-use code
using System;
using System.Threading;

namespace Common
{
    public class Threading
    {
        public static void MarkThreadWith(string mark, object val)
        {
            LocalDataStoreSlot store = Thread.GetNamedDataSlot(mark);
            if (store == null)
            {
                store = Thread.AllocateNamedDataSlot(mark);
            }

            Thread.SetData(store, val);
        }

        public static bool CheckThreadFor(string mark, T val) where T : IEquatable
        {
            LocalDataStoreSlot store = Thread.GetNamedDataSlot(mark);
            if (store == null)
            {
                return false;
            }
            try
            {
                T newSlotData = (T)Thread.GetData(store);
                return newSlotData.Equals(val);
            }
            ///wrong thread
            catch (NullReferenceException)
            {
                return false;
            }
        }
    }
}

Saturday, January 12, 2013

Masterpage location error while creating site from site template


Failed to instantiate file "default.master" from module
"DefaultMasterPage"

I found one possible reason for the error.
File "webtemp_SiteDefinition1.xml" contains something like that:

<?xml version="1.0" encoding="utf-8"?>
<Templates xmlns:ows="Microsoft SharePoint">
  <Template Name="ArchiveSiteDefinition"
            ID="10001">
    <Configuration ID="0"
                   Title="Archive Template Configuration Title"
                   Hidden="FALSE"
                   ImageUrl="/_layouts/images/CPVW.gif"
                   Description="Archive Template Configuration Description"
                   DisplayCategory="Content">
    </Configuration>
  </Template>
</Templates>

Bold text above can't contains white spaces, and maybe other symbols which nonalphanumeric.

Will work - "ArchiveSiteDefinition"
Will not work - "Archive SiteDefinition"

File "webtemp_SiteDefinition1.xml" must be located in folder with name ArchiveSiteDefinition in your studio project.

Monday, September 10, 2012

SPMonitoredScope for Sharepoint 2007

using System;
using Microsoft.Practices.SPG.Common.Logging;
using Microsoft.Practices.SPG.Common.ServiceLocation;

namespace MyApp.Utils
{
    public class MonitoredScope : IDisposable
    {
        DateTime time;
        string _scopeName;

        private ILogger Logger
        {
            get
            {
                return SharePointServiceLocator.Current.GetInstance();
            }
        }

        public MonitoredScope(string scopeName)
        {
            time = DateTime.Now;
            _scopeName = scopeName;
            Logger.TraceToDeveloper(string.Concat("Enter scope: " + scopeName), 
                1313, 
                Microsoft.SharePoint.Administration.TraceSeverity.Monitorable, 
                "TWP");
        }

        public void Dispose()
        {
            DateTime time2 = DateTime.Now;

            Logger.TraceToDeveloper(string.Concat("Leave scope: " + _scopeName, "; Duration: " + (time2 - time).ToString()),
                1313,
                Microsoft.SharePoint.Administration.TraceSeverity.Monitorable,
                "TWP");
        }
    }
}

Save conflict problem

Its very popular problem then you use complex solution with receivers and workflows(WF).
Symptoms are corrupted WF execution and bad ULS messages like that:

-----------------------------------------------------------------------------------------------------
09/04/2012 18:48:23.88 w3wp.exe (0x0CD0)                       0x1940 Windows SharePoint Services   Workflow Infrastructure       88xr Unexpected WinWF Internal Error, terminating workflow Id# 94139810-91fb-457a-9b12-d21a68989b91

09/04/2012 18:48:23.88 w3wp.exe (0x0CD0)                       0x1940 Windows SharePoint Services   Workflow Infrastructure       98d4 Unexpected System.Workflow.Runtime.Hosting.PersistenceException: Save Conflict  Your changes conflict with those made concurrently by another user. If you want your changes to be applied, click Back in your Web browser, refresh the page, and resubmit your changes. ---> Microsoft.SharePoint.SPException: Save Conflict  Your changes conflict with those made concurrently by another user. If you want your changes to be applied, click Back in your Web browser, refresh the page, and resubmit your changes. ---> System.Runtime.InteropServices.COMException (0x81020037): Save Conflict  Your changes conflict with those made concurrently by another user. If you want your changes to be applied, click Back in your Web browser, refresh the page, and resubmit your changes.
-----------------------------------------------------------------------------------------------------

To use WFs and especially with some concurrency code like receivers, you must strongly understand how WFF works.

My case on this problem:

  1. webservice listen for incoming connection and close Nintex(Workflow) task
  2. after close i write some fields to WF item
While my async receiver(updated) on WF item updating, WFF reach the next commit point, in my case its state machine change.

Its funny, the problem was resolved after i swap two lines of code. Task close and WF item update.

You must update WF item first, cause task completion becomes WF active.